allow non-ascii alphanumeric characters in selectors

This commit is contained in:
ConnorSkees 2020-05-21 13:09:20 -04:00
parent b94a2403d0
commit 6b9f68922f
2 changed files with 14 additions and 2 deletions

View File

@ -151,13 +151,20 @@ struct StyleSheetParser<'a> {
path: &'a Path, path: &'a Path,
} }
fn is_selector_char(c: char) -> bool {
c.is_alphanumeric()
|| matches!(
c,
'_' | '-' | '[' | '#' | ':' | '*' | '%' | '.' | '>' | '\\'
)
}
impl<'a> StyleSheetParser<'a> { impl<'a> StyleSheetParser<'a> {
fn parse_toplevel(mut self) -> SassResult<(Vec<Spanned<Stmt>>, Scope)> { fn parse_toplevel(mut self) -> SassResult<(Vec<Spanned<Stmt>>, Scope)> {
let mut rules: Vec<Spanned<Stmt>> = Vec::new(); let mut rules: Vec<Spanned<Stmt>> = Vec::new();
while let Some(Token { kind, .. }) = self.lexer.peek() { while let Some(Token { kind, .. }) = self.lexer.peek() {
match kind { match kind {
'a'..='z' | 'A'..='Z' | '_' | '-' | '0'..='9' _ if is_selector_char(*kind) => rules
| '[' | '#' | ':' | '*' | '%' | '.' | '>' | '\\' => rules
.extend(self.eat_rules(&Selector::new(), &mut Scope::new())?), .extend(self.eat_rules(&Selector::new(), &mut Scope::new())?),
'\t' | '\n' | ' ' => { '\t' | '\n' | ' ' => {
self.lexer.next(); self.lexer.next();

View File

@ -520,3 +520,8 @@ test!(
"$a: aaaaaaaaaaa;\n\n#{$a} {\n color: foo;\n}\n", "$a: aaaaaaaaaaa;\n\n#{$a} {\n color: foo;\n}\n",
"aaaaaaaaaaa {\n color: foo;\n}\n" "aaaaaaaaaaa {\n color: foo;\n}\n"
); );
test!(
toplevel_non_ascii_alphabetic,
" {\n color: red;\n}\n",
"@charset \"UTF-8\";\n {\n color: red;\n}\n"
);