Skip to content

Commit

Permalink
Add comment for unsafe bytes to str
Browse files Browse the repository at this point in the history
  • Loading branch information
jevancc committed Jan 19, 2021
1 parent 8d6eb54 commit a1bfba4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion boa/src/syntax/lexer/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ impl StringLiteral {
let mut code_point_buf = Vec::with_capacity(6);
cursor.take_until(b'}', &mut code_point_buf)?;

// Safty: invalid UTF-8 bytes will be handled by returning Err in the following `u32::from_str_radix`
let code_point_str = unsafe { str::from_utf8_unchecked(code_point_buf.as_slice()) };
// We know this is a single unicode codepoint, convert to u32
// The `code_point_str` should represent a single unicode codepoint, convert to u32
let code_point = u32::from_str_radix(&code_point_str, 16).map_err(|_| {
Error::syntax("malformed Unicode character escape sequence", start_pos)
})?;
Expand Down

0 comments on commit a1bfba4

Please sign in to comment.