Skip to content

Commit 982bf1e

Browse files
committed
fix: avoid infinite loops in attributes parsing
1 parent b3f058b commit 982bf1e

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

crates/oxc_parser/src/lexer/astro.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,13 @@ mod astro_jsx {
201201
/// except whitespace, `=`, `>`, `/`, quotes, and a few others.
202202
///
203203
/// This method reads from the current position until an attribute-name-ending character.
204+
///
205+
/// If the very first byte is a terminator (e.g. a stray `}` or `=`), we consume
206+
/// that single byte so the parser always makes forward progress and cannot
207+
/// enter an infinite loop.
204208
pub(crate) fn read_astro_attribute_name(&mut self) -> Token {
205-
self.token.set_start(self.offset());
209+
let start = self.offset();
210+
self.token.set_start(start);
206211

207212
// Consume all valid attribute name characters (everything except terminators)
208213
let _next_byte = byte_search! {
@@ -213,6 +218,12 @@ mod astro_jsx {
213218
},
214219
};
215220

221+
// If the scan stopped immediately (first byte was a terminator), consume
222+
// that one byte so we always make progress.
223+
if self.offset() == start {
224+
self.consume_char();
225+
}
226+
216227
// We found an ending character, stop here
217228
self.finish_next(Kind::Ident)
218229
}

0 commit comments

Comments
 (0)