From eaa3ce81991563ba8993a45f54f30cd73b075755 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Wed, 27 Dec 2023 13:52:25 +0000 Subject: [PATCH 1/2] Fix a trivial code formatting inconsistency --- test/patch/apply.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/patch/apply.js b/test/patch/apply.js index d5b06ace..baae010c 100755 --- a/test/patch/apply.js +++ b/test/patch/apply.js @@ -525,6 +525,7 @@ describe('patch/apply', function() { + ' line5\n')) .to.equal(false); }); + it('should succeed within fuzz factor', function() { expect(applyPatch( 'line2\n' From 723a2f71f368131f50754298f81e4e136887652d Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Wed, 27 Dec 2023 14:00:08 +0000 Subject: [PATCH 2/2] Add test showing patch from bug https://github.com/kpdecker/jsdiff/issues/177 is handled correctly now --- test/patch/apply.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/patch/apply.js b/test/patch/apply.js index baae010c..266f2adc 100755 --- a/test/patch/apply.js +++ b/test/patch/apply.js @@ -737,6 +737,24 @@ describe('patch/apply', function() { expect(applyPatch(oldContent, patch)).to.equal(newContent); }); + + // Regression test based on bug https://github.com/kpdecker/jsdiff/issues/177 + it('should correctly apply a patch that truncates an entire file', function() { + const patch = parsePatch( + '===================================================================\n' + + '--- index.js\n' + + '+++ index.js\n' + + '@@ -1,3 +1,0 @@\n' + + '-this\n' + + '-\n' + + '-tos\n' + + '\\ No newline at end of file\n' + ); + const fileContents = 'this\n\ntos'; + + expect(applyPatch(fileContents, patch)) + .to.equal(''); + }); }); describe('#applyPatches', function() {