Skip to content

Commit ecb1496

Browse files
authored
fix: do not panic parsing \r\n newlines (#49)
1 parent 937fb2c commit ecb1496

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cst/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,7 @@ impl<'a> CstBuilder<'a> {
23172317
maybe_add_previous_text(last_found_index, i);
23182318
container.raw_append_child(CstNewline::new(CstNewlineKind::CarriageReturnLineFeed).into());
23192319
last_found_index = i + 2;
2320+
chars.next(); // move past the \n
23202321
} else if c == '\n' {
23212322
maybe_add_previous_text(last_found_index, i);
23222323
container.raw_append_child(CstNewline::new(CstNewlineKind::LineFeed).into());
@@ -3594,6 +3595,12 @@ value3: true
35943595
}"#
35953596
);
35963597
}
3598+
// \r\n newlines
3599+
{
3600+
let cst = build_cst("[ 1, 2, /* test */ 3 ]\r\n");
3601+
cst.value().unwrap().as_array().unwrap().ensure_multiline();
3602+
assert_eq!(cst.to_string(), "[\r\n 1,\r\n 2,\r\n /* test */ 3\r\n]\r\n");
3603+
}
35973604
}
35983605

35993606
#[test]
@@ -3852,6 +3859,7 @@ value3: true
38523859
}
38533860
}
38543861

3862+
#[track_caller]
38553863
fn build_cst(text: &str) -> CstRootNode {
38563864
CstRootNode::parse(text, &crate::ParseOptions::default()).unwrap()
38573865
}

0 commit comments

Comments
 (0)