Slugify broken? #355

Closed
pollingj opened this Issue Apr 13, 2012 · 10 comments

2 participants

@pollingj

Is it just me, or it the slugging code not working? It appears to be wiping out any standard characters.

Or am I just going mad?

@mariovisic
Locomotive member

Nope, tis broken

Current status: investimagating

@pollingj

Ok, it's the alphaNumRegexp that's wrong. The \w is grabbing everything.

@mariovisic
Locomotive member

this seems to have broken when doing a fix for non latin characters

2798e15

Any ideas on the correct regex we should be using there that will work with a+z and non latin characters ?

@pollingj

Am I wrong in thinking this wouldn't work either?

var alphaNumRegexp = new RegExp('[^a-zA-Z0-9а-яА-Я\\' + sep + ']', 'g');

as the line with the .replace(alphaNumRegexp, '') would still grab all the characters and replace them with nothing?

@pollingj

Shouldn't it be \W ?

@mariovisic
Locomotive member

I think the original line actually worked fine.

I've rolled back that one line and I'm inputting hello абракадабра testing into the title and getting the slug hello-абракадабра-testing. So shall we just rollback that one line?

@pollingj

ah...yes, sorry I missed the ^.

In theory I think [\W] should work, but I've not tested it thoroughly.

@pollingj

Got it...it's the backslash the code should be

var alphaNumRegexp = new RegExp('[^\\w\\' + sep + ']', 'g');

not

var alphaNumRegexp = new RegExp('[^\w\\' + sep + ']', 'g');

@mariovisic
Locomotive member

Trying out your suggestion

var alphaNumRegexp = new RegExp('[\W]', 'g');

Seems to work fine:

Something => something
Hello there => hello-there
hello абракадабра testing => hello-абракадабра-testing

I'm happy to move to that. Seems to be working fine.

@mariovisic
Locomotive member

Cool same results

I'll change it to this:

var alphaNumRegexp = new RegExp('[^\\w\\' + sep + ']', 'g');

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment