Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug w/ createPatch() when modifying file ending without new line #531

Closed
yev-yev-yev opened this issue Jul 8, 2024 · 0 comments · Fixed by #535
Closed

Bug w/ createPatch() when modifying file ending without new line #531

yev-yev-yev opened this issue Jul 8, 2024 · 0 comments · Fixed by #535

Comments

@yev-yev-yev
Copy link

Minimum code to reproduce

const { createPatch } = require('diff');

const oldContent = `1st line.\n2nd line.\n3rd line.`;
const newContent = `Z11 thing.\nA New thing.\n2nd line.\nNEW LINE.\n3rd line.\n\nSOMETHING ELSE.`;

const diff = createPatch(
  'a.txt',
  oldContent,
  newContent,
  undefined,
  undefined,
  { context: 3 },
);

console.log(diff);

Actual Result

===================================================================
--- a.txt
+++ a.txt
@@ -1,3 +1,7 @@
-1st line.
+Z11 thing.
+A New thing.
\ No newline at end of file
 2nd line.
-3rd line.
+NEW LINE.
+3rd line.
+
+SOMETHING ELSE.
\ No newline at end of file

Expected Result

===================================================================
--- a.txt
+++ a.txt
@@ -1,3 +1,7 @@
-1st line.
+Z11 thing.
+A New thing.
 2nd line.
-3rd line.
\ No newline at end of file
+NEW LINE.
+3rd line.
+
+SOMETHING ELSE.
\ No newline at end of file
ExplodingCabbage added a commit that referenced this issue Jul 29, 2024
* Add (failing) test case from #531

* Fix test I just added (the test itself, not the jsdiff behaviour)

* Fix the new test (but make an old one fail as a side effect)

* Stop allowing newlineIsToken to be passed to patch-generation functions (... and causing them to generate patches that can't be applied)

* Remove impossible case to placate the coverage checker

* Add release notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants