Skip to content
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

Character escaping inside selectors #9

Open
SuggonM opened this issue Sep 29, 2024 · 0 comments
Open

Character escaping inside selectors #9

SuggonM opened this issue Sep 29, 2024 · 0 comments

Comments

@SuggonM
Copy link

SuggonM commented Sep 29, 2024

Using the online demo, I'm getting this error in browser console when trying to parse a rule with special characters escaped:

.wendy\'s {}
parse.js:62 Uncaught 
Error: Unmatched ' (line 1, char 8)
    at parseError (parse.js:62:15)
    at Object.parse (parse.js:110:6)
    at outputUpdated (parse.js:151:19)
    at HTMLTextAreaElement.changed (parse.js:185:2)

which is equivalent to this block:

CSSOM/lib/parse.js

Lines 106 to 113 in 64dfbde

case "'":
index = i + 1;
do {
index = token.indexOf("'", index) + 1;
if (!index) {
parseError("Unmatched '");
}
} while (token[index - 2] === '\\');

Another minor issue is that, round braces and many other invalid-but-escapable selectors remain unchanged when using toString(). Perhaps we could somehow ensure that the returned selector of toString() method is always valid?

.wendy(s) {}
// current: .wendy(s) {}
// suggestion: .wendy\(s\) {}
CSSOM.parse('.wendy(s) {}').toString();

I'm trying to parse a fairly large CSS spritesheet that has a lot of these characters, so fixing this would be of huge help!

Another suggestion that may or may not be relevant to this repository is, using a CSS escaping module. Mathias has made one in cssesc and it addresses both cases mentioned above, for example here and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant