From 6b9f68922f1f7ec8f7183727f08d67fd8a9eea93 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 21 May 2020 13:09:20 -0400 Subject: [PATCH] allow non-ascii alphanumeric characters in selectors --- src/stylesheet.rs | 11 +++++++++-- tests/selectors.rs | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/stylesheet.rs b/src/stylesheet.rs index 6c37e86..1a75f0d 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -151,13 +151,20 @@ struct StyleSheetParser<'a> { path: &'a Path, } +fn is_selector_char(c: char) -> bool { + c.is_alphanumeric() + || matches!( + c, + '_' | '-' | '[' | '#' | ':' | '*' | '%' | '.' | '>' | '\\' + ) +} + impl<'a> StyleSheetParser<'a> { fn parse_toplevel(mut self) -> SassResult<(Vec>, Scope)> { let mut rules: Vec> = Vec::new(); while let Some(Token { kind, .. }) = self.lexer.peek() { match kind { - 'a'..='z' | 'A'..='Z' | '_' | '-' | '0'..='9' - | '[' | '#' | ':' | '*' | '%' | '.' | '>' | '\\' => rules + _ if is_selector_char(*kind) => rules .extend(self.eat_rules(&Selector::new(), &mut Scope::new())?), '\t' | '\n' | ' ' => { self.lexer.next(); diff --git a/tests/selectors.rs b/tests/selectors.rs index 3ae461b..d0b8212 100644 --- a/tests/selectors.rs +++ b/tests/selectors.rs @@ -520,3 +520,8 @@ test!( "$a: aaaaaaaaaaa;\n\n#{$a} {\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" +);