gosimple / slug

URL-friendly slugify with multiple languages support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

slug.Make() returns non-slug

micabot opened this issue · comments

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.

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

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 🎊

Thanks for the quick fix!