consume utf8 bom in parser, not lexer

This commit is contained in:
Connor Skees 2020-08-10 06:53:00 -04:00
parent c19eda6f89
commit 5bf03c15d6
3 changed files with 4 additions and 11 deletions

View File

@ -40,12 +40,7 @@ impl<'a> Iterator for Lexer<'a> {
impl<'a> Lexer<'a> {
pub fn new(file: &'a Arc<File>) -> Lexer<'a> {
Lexer {
buf: file
.source()
.trim_start_matches("\u{ef}\u{bb}\u{bf}")
.trim_start_matches("\u{feff}")
.chars()
.peekable(),
buf: file.source().chars().peekable(),
pos: 0,
file,
}

View File

@ -96,6 +96,9 @@ impl<'a> Parser<'a> {
pub fn parse(&mut self) -> SassResult<Vec<Stmt>> {
let mut stmts = Vec::new();
// Allow a byte-order mark at the beginning of the document.
self.consume_char_if_exists('\u{feff}');
self.whitespace();
stmts.append(&mut self.load_modules()?);

View File

@ -101,8 +101,3 @@ test!(
"\u{feff}a {\n color: red\n}\n",
"a {\n color: red;\n}\n"
);
test!(
file_begins_with_bom,
"\u{ef}\u{bb}\u{bf}a {\n color: red\n}\n",
"a {\n color: red;\n}\n"
);