Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repair explosive memory leak in GritQL parser #5033

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/biome_grit_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<'src> GritLexer<'src> {
fn lex_token(&mut self, current: u8) -> GritSyntaxKind {
match current {
b'\n' | b'\r' => {
debug_assert!(self.consume_newline());
self.consume_newline();
NEWLINE
}
b'\t' | b' ' => self.consume_whitespaces(),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_grit_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod literals;
mod parse_error;
mod patterns;
mod predicates;
mod tests;

use crate::constants::*;
use crate::token_source::GritTokenSource;
Expand Down
11 changes: 11 additions & 0 deletions crates/biome_grit_parser/src/parser/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![cfg(test)]

use crate::parse_grit;

/// This pattern should be parseable, but previously caused explosive memory usage
#[test]
fn parse_language_declaration() {
let code = "language js\n";
let parse = parse_grit(code);
assert!(parse.diagnostics().is_empty());
}