-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forward slash is valid url character but removed #98
Comments
Hi! I am new here, I was wondering if I could try to fix this issue? |
Generally speaking I don't think adding additional |
This is probably an over-engineered and inelegant solution, but I can't tell so here it is anyway: It would be a breaking change, but perhaps the
|
Thanks @Trott, so now we are building a wrapper for regular expressions, although I really do see your point. I like the idea of having the strict mode by default in a next major. I think the main confusion stems from the fact that you have to deal with the existing remove regex by default. I imagine people feeling much more comfortable about crafting their own remove regex from scratch but I might be wrong. |
I was thinking of two potential solutions:
There are some attempts to combine or simplify RegExs: Not sure if that is a reliable solution |
It would also allow one to alter other settings so the possibilities become pretty substantial. A mode plugin could alter the charmap, so there could be an easy way to add Pinyin for users who need that, but it can be omitted by default for users who don't need thousands of characters increasing the size of their library. |
This is perhaps more maintainable and understandable than passing in a function slugifyWithSlashes(myString) {
return myString.split('/').map((val) => slugify(val)).join('/')
} |
Repeating what I wrote in #131 (comment) here: I always considered a slug to be a URL element, not a path, so keeping slashes is very much unexpected to me. To me, the canonical use case is "I have a title of an article and I want to convert that article title to a component in a URL." So I might have a blog at www.example.com/my-awesome-blog. And if I post something today, it might end up in www.example.com/my-awesome-blog/2021/08/28/some-slug-value-here. So if I have an article titled "Better A/B Testing", I want a slug like The use case where keeping slashes is expected seems unusual to me. Can you explain how this came up for you? |
The use case is when constructing a url with multiple slug parts: county: Los Angeles With the current functionality you could do:
But with the suggested feature it would be:
This is an example for just two url parts, but there could be n number |
Interesting. For what it's worth, I'd be inclined to put all the URL parts into an array and use urlParts = ['Los Angeles', 'Culver City', 'California', 'United States of America', '99122', 'Earth']
urlParts.map(slugify).join('/') Being able to run |
Sure, the performance benefit is negligible. But one RegEx is more performant than a loop. For me it's the convenience and to make code more DRY. Forward slashes are very closely related to slugs so either way, some folks will need the workaround! I will understand if you don't feel it's a feature slugify should support. |
By the way, the use case suggested here would result in a bug in user code if a county or city (or any other string supplied) contained a slash in its name, whereas using an array with |
Fair enough, closing! |
Slugify is designed to support valid url characters. However if I pass in a forward slash:
The result is:
Where I would expect:
This can of course be mitigated by changing the remove RegEx adding
\/
:But this is not a very elegant solution. Ideally there would be an ignore/exclude character feature?
The text was updated successfully, but these errors were encountered: