[Update] Update slugify() again.

* Reduced the regexp by switching fully to ranges.
* Switched replacement character to underscore.
* Dropped lowercasing.
This commit is contained in:
Thomas M. Edwards 2020-02-25 00:56:36 -06:00
parent 2d91f1ce96
commit ea69d81375

View file

@ -94,9 +94,9 @@ func slugify(original string) string {
// less-than, equals, greater-than, question, at, left bracket, backslash, right
// bracket, caret, backquote/grave, left brace, pipe/vertical-bar, right brace, tilde,
// delete, C1 controls.
invalidRe := regexp.MustCompile(`[\x00-\x20!"#$%&'()*+,\-./:;<=>?@[\\\]^\x60{|}~\x7f-\x9f]+`)
illegalRe := regexp.MustCompile(`[\x00-\x20!-/:-@[-^\x60{-\x9f]+`)
return strings.ToLower(invalidRe.ReplaceAllLiteralString(original, "-"))
return illegalRe.ReplaceAllLiteralString(original, "_")
}
func stringSliceContains(haystack []string, needle string) bool {