mdevils/css-selector-parser

Issue/Error with `/` in classnames/selectors

Closed this issue · 1 comments

Hi,

while there seems to be an identifier for the / character, the lib and its tests fail when using / character in a classname, i.e. .u-1/2. If you wonder — that’s perfectly fine CSS. Actually, I was also trying to provide it in an escaped way (\/ which is suggested to be used in CSS files) but it resulted in the exact same error, described now:

In the test.js file I added the following assertion:
assertEquals('.u-1/2', parser.render(parser.parse('.u-1\/2')));
This fails with:
Error: Rule expected but "/" found.

And the parser itself doesn’t seem to work as well with it. Found out via oddbird/true#68.

I’m sorry, I couldn’t immediately identify the issue and submit a PR so it’d be lovely if I could either get some hints or someone else or the author/maintainer could try to fix this?

Cheers,
—Anselm

Hello @anselmh,

It looks like you are escaping slash improperly.

Instead of assertEquals('.u-1/2', parser.render(parser.parse('.u-1\/2'))); try assertEquals('.u-1/2', parser.render(parser.parse('.u-1\\/2')));; because by putting one slash, you are escaping a slash in JavaScript string, and since slash does not need escaping, you get just / in your string. Try console.log('123\/456') and console.log('123\\/456').