Skip to content

Commit

Permalink
fix: do not panic parsing \r\n newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 25, 2024
1 parent 937fb2c commit b2691e6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,7 @@ impl<'a> CstBuilder<'a> {
maybe_add_previous_text(last_found_index, i);
container.raw_append_child(CstNewline::new(CstNewlineKind::CarriageReturnLineFeed).into());
last_found_index = i + 2;
chars.next(); // move past the \n
} else if c == '\n' {
maybe_add_previous_text(last_found_index, i);
container.raw_append_child(CstNewline::new(CstNewlineKind::LineFeed).into());
Expand Down Expand Up @@ -3594,6 +3595,12 @@ value3: true
}"#
);
}
// \r\n newlines
{
let cst = build_cst("[ 1, 2, /* test */ 3 ]\r\n");
cst.value().unwrap().as_array().unwrap().ensure_multiline();
assert_eq!(cst.to_string(), "[\r\n 1,\r\n 2,\r\n /* test */ 3\r\n]\r\n");
}
}

#[test]
Expand Down Expand Up @@ -3852,6 +3859,7 @@ value3: true
}
}

#[track_caller]
fn build_cst(text: &str) -> CstRootNode {
CstRootNode::parse(text, &crate::ParseOptions::default()).unwrap()
}
Expand Down

0 comments on commit b2691e6

Please sign in to comment.