Fix crash due to trailing newlines in string nodes at EOF

Fixes #782
pull/789/head
Wilfred Hughes 2024-11-14 13:51:14 +07:00
parent 0412e13fcc
commit 549cb483fe
5 changed files with 19 additions and 1 deletions

@ -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

@ -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 -

@ -0,0 +1,3 @@
run: |
set -x
git clone https://github.com/torvalds/linux

@ -0,0 +1,2 @@
run: |
git clone https://github.com/torvalds/linux

@ -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];
}