Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/oxc_parser/src/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ fn parse_int_without_underscores(s: &str, kind: Kind) -> Result<f64, &'static st
Kind::Decimal => Ok(parse_decimal(s)),
Kind::Binary => Ok(parse_binary(&s[2..])),
Kind::Octal => {
let s = if s.starts_with("0o") || s.starts_with("0O") {
&s[2..]
// Octals always begin with `0`. Trim off leading `0`, `0o` or `0O`.
let second_byte = s.as_bytes()[1];
let s = if second_byte == b'o' || second_byte == b'O' {
// SAFETY: We just checked that 2nd byte is ASCII, so slicing off 2 bytes
// must be in bounds and on a UTF-8 character boundary.
unsafe { s.get_unchecked(2..) }
} else {
s // legacy octal
&s[1..] // legacy octal
};
Ok(parse_octal(s))
}
Expand Down