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

")" not found when trying to import font with multiple weights #116

Open
RahulLanjewar93 opened this issue Jan 31, 2023 · 3 comments
Open

Comments

@RahulLanjewar93
Copy link

RahulLanjewar93 commented Jan 31, 2023

CSSOM/lib/parse.js

Lines 333 to 358 in a469aae

case ";":
switch (state) {
case "value":
styleRule.style.setProperty(name, buffer.trim(), priority);
priority = "";
buffer = "";
state = "before-name";
break;
case "atRule":
buffer = "";
state = "before-selector";
break;
case "importRule":
importRule = new CSSOM.CSSImportRule();
importRule.parentStyleSheet = importRule.styleSheet.parentStyleSheet = styleSheet;
importRule.cssText = buffer + character;
styleSheet.cssRules.push(importRule);
buffer = "";
state = "before-selector";
break;
default:
buffer += character;
break;
}
break;

This fails for import rules for fonts which have multiple font weights.

Example :- @import url(https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400&display=swap);

I get the error:- ")" not found.
I am guessing it's due to semicolon being encountered first before closing the bracket.

@RahulLanjewar93
Copy link
Author

@papandreou @NV Any idea how we can resolve this?

@papandreou
Copy link
Contributor

Yeah, looks like the parser doesn't handle semicolons within url(...).

One possible workaround is to add quotes around the url:

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400&display=swap');

Or you can percent-encode the semicolon:

@import url(https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300%3B400&display=swap);

@RahulLanjewar93
Copy link
Author

Thanks for the workaround.

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

2 participants