diff --git a/components/bower.json b/components/bower.json index 722047ba..fd486986 100644 --- a/components/bower.json +++ b/components/bower.json @@ -1,6 +1,6 @@ { "name": "jsdiff", - "version": "3.3.0", + "version": "3.3.1", "main": [ "diff.js" ], diff --git a/components/component.json b/components/component.json index 7e140fca..8e262b88 100644 --- a/components/component.json +++ b/components/component.json @@ -6,7 +6,7 @@ "diff", "text" ], - "version": "3.3.0", + "version": "3.3.1", "scripts": [ "diff.js" ], "main": "diff.js", "license": "BSD" diff --git a/package.json b/package.json index 8b13337e..36308d96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "diff", - "version": "3.3.0", + "version": "3.3.1", "description": "A javascript text diff implementation.", "keywords": [ "diff", diff --git a/release-notes.md b/release-notes.md index 63de9ac1..43b9d2b3 100644 --- a/release-notes.md +++ b/release-notes.md @@ -2,7 +2,14 @@ ## Development -[Commits](https://github.com/kpdecker/jsdiff/compare/v3.3.0...master) +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.3.1...master) + +## v3.3.1 - September 3rd, 2017 +- [#141](https://github.com/kpdecker/jsdiff/issues/141) - Cannot apply patch because my file delimiter is "/r/n" instead of "/n" +- [#192](https://github.com/kpdecker/jsdiff/pull/192) - Fix: Bad merge when adding new files (#189) +- correct spelling mistake - 21fa478 + +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.3.0...v3.3.1) ## v3.3.0 - July 5th, 2017 - [#114](https://github.com/kpdecker/jsdiff/issues/114) - /patch/merge not exported diff --git a/src/patch/apply.js b/src/patch/apply.js index e6509260..e830fc11 100644 --- a/src/patch/apply.js +++ b/src/patch/apply.js @@ -85,6 +85,10 @@ export function applyPatch(source, uniDiff, options = {}) { toPos = hunk.oldStart + hunk.offset + diffOffset - 1; diffOffset += hunk.newLines - hunk.oldLines; + if (toPos < 0) { // Creating a new file + toPos = 0; + } + for (let j = 0; j < hunk.lines.length; j++) { let line = hunk.lines[j], operation = line[0], diff --git a/src/util/distance-iterator.js b/src/util/distance-iterator.js index 8360f43e..73be1f80 100644 --- a/src/util/distance-iterator.js +++ b/src/util/distance-iterator.js @@ -39,7 +39,7 @@ export default function(start, minLine, maxLine) { return iterator(); } - // We tried to fit hunk before text beginning and beyond text lenght, then + // We tried to fit hunk before text beginning and beyond text length, then // hunk can't fit on the text. Return undefined }; } diff --git a/test/patch/apply.js b/test/patch/apply.js index 96ff4703..67965662 100755 --- a/test/patch/apply.js +++ b/test/patch/apply.js @@ -461,6 +461,23 @@ describe('patch/apply', function() { + 'line5\n'); }); + it('should create a file', function() { + expect(applyPatch('', + + '--- test\theader1\n' + + '+++ test\theader2\n' + + '@@ -0,0 +1,4 @@\n' + + '+line1\n' + + '+line2\n' + + '+line3\n' + + '+line4\n')) + .to.equal( + 'line1\n' + + 'line2\n' + + 'line3\n' + + 'line4\n'); + }); + it('should erase a file', function() { expect(applyPatch( 'line1\n'