Skip to content

Commit

Permalink
Fix line terminator and escape followed by unicode char
Browse files Browse the repository at this point in the history
  • Loading branch information
jevancc committed Jan 19, 2021
1 parent 83e8647 commit 1c170a5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions boa/src/syntax/lexer/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl StringLiteral {
.filter(|next_ch| next_ch.is_digit(10))
.is_none() =>
{
buf.push('\0' as u16)
buf.push('\u{0000}' as u16 /* NULL */)
}
'x' => {
Self::take_hex_escape_sequence(cursor, Some(&mut buf))?;
Expand All @@ -153,20 +153,25 @@ impl StringLiteral {
// Grammar: \ LineTerminatorSequence
// LineContinuation is the empty String. Do nothing and continue lexing.
}
_ => buf.push(escape_ch as u16),
_ => {
if escape_ch.len_utf16() == 1 {
buf.push(escape_ch as u16);
} else {
buf.extend(escape_ch.encode_utf16(&mut [0u16; 2]).iter());
}
}
};
}
Some(next_ch) => {
Some('\u{0028}') /* <LS> */ => buf.push('\u{0028}' as u16),
Some('\u{0029}') /* <PS> */ => buf.push('\u{0029}' as u16),
Some(next_ch) if !Self::is_line_terminator(next_ch) => {
if next_ch.len_utf16() == 1 {
buf.push(next_ch as u16);
} else {
let mut code_units_buf = [0u16; 2];
let code_units_buf = next_ch.encode_utf16(&mut code_units_buf);

buf.extend(code_units_buf.iter());
buf.extend(next_ch.encode_utf16(&mut [0u16; 2]).iter());
}
}
None => {
_ => {
return Err(Error::from(io::Error::new(
ErrorKind::UnexpectedEof,
"unterminated string literal",
Expand Down

0 comments on commit 1c170a5

Please sign in to comment.