I was just looking through some old posts and I noticed that a "ß" in a question title magically turns into an "ss" in the URL slug.

What function is being used to format the slugs? Clearly it has some advanced behavior in terms of determining character equivalents, rather than just ignoring special characters.

(Note: I just tried this with "fi" and "fl" and they're not converted to "fi" and "fl"...)


Assuming the current implementation is still similar (although Jeff mentions looking into another approach)...

Taking 80 characters from the raw title, , ,, ., /, \, and _ are replaced with -, collapsing consecutive such characters into a single dash. Latin alphabetic characters are converted to lowercase, and the following substitutions are made:

àåáâäãåą => a
èéêëę    => e
ìíîïı    => i
òóôõöø   => o
ùúûü     => u
çćč      => c
żźž      => z
śşš      => s
ñń       => n
ýŸ       => y
ł        => l
đ        => d
ß        => ss
ğ        => g
Þ        => th
ĥ        => h
ĵ        => j

Finally, if the above process resulted in the trailing dash, it is removed.

  • Only these particular substitutions? Is there not some library function which can de-adorn any Latin-ish character?
    – jtbandes
    Mar 28 '12 at 21:11
  • Do you describe an observation, or do you know the actual algorithm? Mar 28 '12 at 21:15
  • 4
    TIM STONE KNOWS ALL @CodeInChaos Mar 28 '12 at 21:17
  • I would have used something like s.Normalize(NormalizationForm.FormD).Where(c=>CharUnicodeInfo.GetUnicodeCategory(c)!=UnicodeCategory.NonSpacingMark); to get rid of diacritics. Which would not have handles ß. Mar 28 '12 at 21:17
  • 5
    See Jeff's answer in Non US-ASCII characters dropped from full (profile) URL, @jtbandes.
    – Arjan
    Mar 28 '12 at 21:19
  • @Arjan Ah, that's more up-to-date than where I was pulling the list from, good stuff.
    – Tim Stone
    Mar 28 '12 at 21:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .