Home / Blog / Why slugify() has a special case for ß

June 30, 2026· Wine World Map

Why slugify() has a special case for ß

Every region and district on Wine World Map has a URL slug. Bordeaux is /regions/bordeaux, Châteauneuf-du-Pape is /districts/chateauneuf-du-pape, and the slug generator that produces both is twelve lines of TypeScript. Eleven of those lines are boring. The twelfth exists because of a single letter that German wine country happens to be full of.

The boring eleven lines

export function slugify(name: string): string {
  return name
    .normalize('NFD')
    .replace(/[\u0300-\u036f]/g, '')   // strip combining diacritics
    .replace(/ß/g, 'ss')               // see below
    .toLowerCase()
    .replace(/['\u2019]/g, '')         // ' and ’
    .replace(/&/g, '-and-')
    .replace(/[^a-z0-9]+/g, '-')
    .replace(/^-+|-+$/g, '')
}

NFD ("canonical decomposition") splits accented characters into a base letter plus a combining-diacritic codepoint. é becomes e + U+0301. Then the regex strips everything in the combining-mark range, leaving the base letter. This is the well-known trick and it handles almost everything you throw at it:

| Input | NFD result | Slug | |---|---|---| | Châteauneuf-du-Pape | Cha^teauneuf-du-Pape | chateauneuf-du-pape | | Saint-Émilion | Saint-E´milion | saint-emilion | | Côte de Beaune | Co^te de Beaune | cote-de-beaune | | Rías Baixas | Ri´as Baixas | rias-baixas | | Tokaj-Hegyalja | (no change) | tokaj-hegyalja |

The grave on à, the acute on é, the circumflex on ô, the tilde on ñ, the umlaut on ü — all of them decompose cleanly into a base letter and a mark that the regex eats.

The letter that doesn't decompose

Then we tried to import German wine regions.

slugify('Württemberg')   // 'wurttemberg'  ✓
slugify('Großlage')      // 'gro-lage'     ✗

ß (sharp s, eszett) is not a decorated letter. It's its own codepoint with its own identity, and NFD leaves it alone because there is nothing to decompose. Lowercasing leaves it alone too — ß is already lowercase. The diacritic-stripping regex doesn't match it. So it sails through to the [^a-z0-9] catch-all and gets replaced with a hyphen, which is why Großlage came out as gro-lage and Großheubach came out as gro-heubach.

The German orthographic rule is that ß transliterates to ss when you can't type it. That's the rule a German speaker would apply on a US keyboard, and it's the rule that makes großlage and grosslage resolve to the same slug, which is what we want for the deduper downstream. Hence the one-line special case, which has to run before lowercasing because 'ß'.toLowerCase() is 'ß', not 'ss'.

There's a capital ẞ too (U+1E9E, introduced into Unicode in 2008). We don't have any region names that start with one, but the regex handles it anyway because lowercasing it gives ß, which then gets caught by the special case. Belt and suspenders.

Other things that look like diacritics but aren't

While we're here, a few other characters that pretend to be diacritics and aren't:

  • Ø (Danish/Norwegian, as in Aalborg's hinterland): a distinct letter, not an O with a stroke as far as NFD is concerned. We don't have any wine regions using it, so we haven't bothered.
  • Ł (Polish): same story. There's a tiny Polish wine industry but no region in our import yet has Ł.
  • Æ, Œ (ligatures): NFKD decomposes them, but NFD doesn't. We don't currently use NFKD because it also decomposes things we want to keep (like full-width punctuation in a couple of Japanese entries). The Provençal Coteaux d'Aix writes its appellation in plain Latin letters, so we've gotten away with it.

When one of these eventually breaks something I'll add another line. The slugify function is a list of cases we've actually hit, not a theoretical model of human writing.

The collision check that catches the rest

Whatever the function produces, the import script checks for slug collisions against existing rows before inserting. A collision means two distinct regions normalized to the same string, and the script stops and asks for a manual disambiguation suffix — usually the country code: rioja-es vs rioja-ar if Argentina ever decides to mint a rival appellation. So far the worst collision we've seen is saint-emilion against itself, which is the deduper's job, not the slug's.

The lesson is the small one: Unicode normalization handles the diacritic case beautifully and the ligature case acceptably, but it makes no claim to handle every letter that looks like a decorated Latin character. ß is a letter, not an accent. If your data has Germans in it, your slug function knows it.

#slugs#unicode#i18n