question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forward slash is valid url character but removed

See original GitHub issue

Slugify is designed to support valid url characters. However if I pass in a forward slash:

slugify(`Something/Another thing`, { lower: true })

The result is:

somethinganother-thing

Where I would expect:

something/another-thing

This can of course be mitigated by changing the remove RegEx adding \/:

console.log(slugify(`Something/Another thing`, { lower: true, remove: /[^\w\s$*_+~.()'"!\-:@\/]+/g }));

But this is not a very elegant solution. Ideally there would be an ignore/exclude character feature?

console.log(slugify(`Something/Another thing`, { lower: true, exclude: '/' }));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Trottcommented, Aug 27, 2021

This is perhaps more maintainable and understandable than passing in a remove regular expression.

function slugifyWithSlashes(myString) {
 return myString.split('/').map((val) => slugify(val)).join('/')
}
1reaction
Trottcommented, Dec 10, 2020

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 strict option can be deprecated in favor of a mode setting that affects the defaults of things like the remove regex. slugify can ship with a strict mode and loose (or sloppy or whatever you want to call it) mode, but people could add their own and perhaps even ship them as separate packages, effectively being a plugin:

const slugify = require('slugify')
const slashesMode = require('slugify-plugin-slashes-mode')

slugify.addMode(slashesMode) 
slugify.mode = 'slashes'

// Or maybe `.use()` or `.useMode()` to do both of the above two lines at once?
Read more comments on GitHub >

github_iconTop Results From Across the Web

urlencoded Forward slash is breaking URL - Stack Overflow
I am using urlencode() while preparing the search URL and urldecode() while reading the search URL. Problem. Only the forward slash character is...
Read more >
Should You Have a Trailing Slash at the End of URLs? - Ahrefs
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. But should you...
Read more >
regex last slash in url - Ristorante L'Attracco.
If your REGEX includes that character at the end, then a visit to the same URL but without the forward-slash wouldn't match. 4:...
Read more >
URL encoding slash character ('/') and Apache web servers
Hi, I'm facing a problem with IIIF Image API 1.1 (it should be the same with API 2.0 though). I'm using : -...
Read more >
What is a trailing slash? - Ryte Wiki
This should be taken into account mostly in cases where websites can be accessed through a URL with a different number of trailing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found