gosimple / slug

URL-friendly slugify with multiple languages support.
Mozilla Public License 2.0
1.17k stars 109 forks source link

slug.Make() returns non-slug #25

Closed micabot closed 5 years ago

micabot commented 5 years ago

Hi there! Thanks for this awesome lib! I'm not sure if this is a valid use-case or not, but I've found a set of custom substitutions that seem to break Make(). In the code below, IsSlug() returns false for every item in slugs.

names := []string{
    "Ciudad Autónoma de Buenos Aires AR",
    "Córdoba AR",
    "Entre Ríos AR",
    "Neuquén AR",
    "Tucumán AR",
}

slug.CustomSub = map[string]string{
    "AR": "",
    "BR": "",
    "CL": "",
    "UY": "",
}

slug.CustomRuneSub = map[rune]string{
    'á': "aa",
    'é': "ee",
    'í': "ii",
    'ó': "oo",
    'ú': "uu",
    ' ': "_",
}

var slugs []string

for _, n := range names {
    slugs = append(slugs, slug.Make(n))
}

I've already found a way to work around this in my code, using SubstituteRune() first.

matrixik commented 5 years ago

Thank you for the report. Will check it when I will have time at home.

matrixik commented 5 years ago

Turns out I was trimming only - at the beginning and the end of the string but IsSlug is more strict (in a good way). All your strings got _ at the end after slug.Make call.

Fixed now. Thank you for reporting :confetti_ball:

micabot commented 5 years ago

Thanks for the quick fix!