diff --git a/crates/toml_edit/src/parser/trivia.rs b/crates/toml_edit/src/parser/trivia.rs index be583d03..f85b7e10 100644 --- a/crates/toml_edit/src/parser/trivia.rs +++ b/crates/toml_edit/src/parser/trivia.rs @@ -5,6 +5,7 @@ use winnow::combinator::empty; use winnow::combinator::eof; use winnow::combinator::fail; use winnow::combinator::opt; +use winnow::combinator::peek; use winnow::combinator::repeat; use winnow::combinator::terminated; use winnow::prelude::*; @@ -90,12 +91,15 @@ pub(crate) fn ws_newlines<'i>(input: &mut Input<'i>) -> PResult<()> { // note: this rule is not present in the original grammar // ws-comment-newline = *( ws-newline-nonempty / comment ) pub(crate) fn ws_comment_newline<'i>(input: &mut Input<'i>) -> PResult<()> { - ( - repeat(0.., (take_while(0.., WSCHAR), opt(comment), newline)).map(|()| ()), - take_while(0.., WSCHAR), - ) - .void() - .parse_next(input) + let _ = ws.parse_next(input)?; + + dispatch! {opt(peek(any)); + Some(b'#') => (comment, newline, ws_comment_newline).void(), + Some(b'\n') => (newline, ws_comment_newline).void(), + Some(b'\r') => (newline, ws_comment_newline).void(), + _ => empty, + } + .parse_next(input) } // note: this rule is not present in the original grammar diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index 62b33bdd..092d3c3d 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -309,13 +309,12 @@ TOML parse error at line 1, column 1 bad!( "a = [ \r ]", str![[r#" -TOML parse error at line 1, column 7 +TOML parse error at line 1, column 8 | 1 | a = [ ] - | ^ -invalid array -expected `]` + | ^ + "#]] );