sindresorhus / slugify

Slugify a string
MIT License
2.56k stars 81 forks source link

dot "." is legal in a URL but it is replaced with "-" #55

Closed terchris closed 1 year ago

terchris commented 3 years ago

HI Sindre I have been using your slugify and I find it very useful. So thank you for offering it.

I discovered that a url containing a dot is converted. Eg: version3.1 is converted to version3-1

This created problems when I'm creating slugs for URLs like https://api.insightly.com/v3.1/Help

According to the spec of url written by Tim Berners-Lee back in 1994 it is legal to have a dot "." (punktum) in a url. https://www.w3.org/Addressing/URL/url-spec.txt

Is there a way to instruct slugify to not convert "." to "-" ?

sindresorhus commented 3 years ago

There are lots of characters that are allowed in a URL that are replaced by a dash. That's how slugification usually works.

We could potentially add an option with an array of characters to preserve, but as a user, I think version3-1 is perfectly fine.

GrosSacASac commented 3 years ago

As I understands, slugify should work nice with filenames, and having a dot in the filename can change how it is opened by default

Xendiadyon commented 3 years ago

A setting with characters to preserve would be great!

iffjey commented 3 years ago

I also encountered this issue during migration of a blog. In a previous system we used «underscore» as valid part of slug. And now in Gatsby it's impossible to save previous structure/paths. Would be really awesome to see this improvement.

iffjey commented 3 years ago

@sindresorhus If you okay with a proposal to add an option to preserve some characters, I can make a PR

p.s. oh crap, just noticed that you're on a vacation, sry :)

sindresorhus commented 3 years ago

PR welcome. You can use https://github.com/sindresorhus/slugify/commit/2aa56594af9309961565e5c33d09dc9a575f3e39 as an example of what's expected of the PR.

iffjey commented 3 years ago

Also I noticed, that Gatsby uses v.1.x.x of slugify, so this change probably won't benefit me 😅. But I will try anyway. Thank you

sailuna commented 2 years ago

Hello @sindresorhus . Is it still perhaps possible to create a function that preserves a dot "." in the url? :/