From c7efee79a873f5af089f62b65c305befef749de4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Jul 2024 13:24:51 -0500 Subject: [PATCH] perf(parser): Resolve regression from stackoverflow protect --- Cargo.lock | 4 ++-- crates/toml_edit/Cargo.toml | 2 +- crates/toml_edit/src/parser/trivia.rs | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37092b1d..495a677b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1175,9 +1175,9 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93b68c91a1b24c7456960ac3290e86a316f3aefcda89c4cad24ae3eda34f4411" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] diff --git a/crates/toml_edit/Cargo.toml b/crates/toml_edit/Cargo.toml index 0898f9c8..85640dd6 100644 --- a/crates/toml_edit/Cargo.toml +++ b/crates/toml_edit/Cargo.toml @@ -41,7 +41,7 @@ unbounded = [] [dependencies] indexmap = { version = "2.0.0", features = ["std"] } -winnow = { version = "0.6.17", optional = true } +winnow = { version = "0.6.18", optional = true } serde = { version = "1.0.145", optional = true } kstring = { version = "2.0.0", features = ["max_inline"], optional = true } toml_datetime = { version = "0.6.8", path = "../toml_datetime" } diff --git a/crates/toml_edit/src/parser/trivia.rs b/crates/toml_edit/src/parser/trivia.rs index acf678b9..5630bca9 100644 --- a/crates/toml_edit/src/parser/trivia.rs +++ b/crates/toml_edit/src/parser/trivia.rs @@ -96,13 +96,13 @@ pub(crate) fn ws_comment_newline(input: &mut Input<'_>) -> PResult<()> { loop { let _ = ws.parse_next(input)?; - dispatch! {opt(peek(any)); - Some(b'#') => (comment, newline).void(), - Some(b'\n') => (newline).void(), - Some(b'\r') => (newline).void(), - _ => empty, + let next_token = opt(peek(any)).parse_next(input)?; + match next_token { + Some(b'#') => (comment, newline).void().parse_next(input)?, + Some(b'\n') => (newline).void().parse_next(input)?, + Some(b'\r') => (newline).void().parse_next(input)?, + _ => break, } - .parse_next(input)?; let end = input.checkpoint(); if start == end {