diff --git a/CHANGELOG.md b/CHANGELOG.md index 0722c14cb..73542e406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## 0.62 (unreleased) +### Diffing + +Improved handling of multiline strings, which could cause a crash if +they occurred at the end of the file. This was particularly noticeable +with YAML. + ## 0.61 (released 24th October 2024) **Recommended git configuration has changed! Please update your diff --git a/sample_files/compare.expected b/sample_files/compare.expected index 0b9d61425..b13c8b393 100644 --- a/sample_files/compare.expected +++ b/sample_files/compare.expected @@ -160,6 +160,9 @@ f761255d521267ace4f4887a21664a12 - sample_files/multiline_string_1.ml sample_files/multiline_string_2.ml ed80815053ba156505d156277d0f4195 - +sample_files/multiline_string_eof_1.yml sample_files/multiline_string_eof_2.yml +ba8a8e7ed2f4b519feaa391fd05c95fe - + sample_files/nest_1.rs sample_files/nest_2.rs d3a799fe2cd9d81aa251c96af5cd9711 - diff --git a/sample_files/multiline_string_eof_1.yml b/sample_files/multiline_string_eof_1.yml new file mode 100644 index 000000000..40a6a45a5 --- /dev/null +++ b/sample_files/multiline_string_eof_1.yml @@ -0,0 +1,3 @@ +run: | + set -x + git clone https://github.com/torvalds/linux diff --git a/sample_files/multiline_string_eof_2.yml b/sample_files/multiline_string_eof_2.yml new file mode 100644 index 000000000..16b6118cd --- /dev/null +++ b/sample_files/multiline_string_eof_2.yml @@ -0,0 +1,2 @@ +run: | + git clone https://github.com/torvalds/linux diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs index 911eba473..80a40eab6 100644 --- a/src/parse/syntax.rs +++ b/src/parse/syntax.rs @@ -258,7 +258,11 @@ impl<'a> Syntax<'a> { content = &content[..content.len() - 1]; } - if kind == AtomKind::Comment && content.ends_with('\n') { + // If a parser adds a trailing newline to the atom, discard + // it. It produces worse diffs: we'd rather align on real + // content, and complicates handling of trailing newlines at + // the end of the file. + if content.ends_with('\n') { position.pop(); content = &content[..content.len() - 1]; }