diff --git a/README.md b/README.md index d2df2eaf..39842cc2 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,10 @@ or Just like JsDiff.createTwoFilesPatch, but with oldFileName being equal to newFileName. - + * `JsDiff.structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options)` - returns an object with an array of hunk objects. - This method is similar to createTwoFilesPatch, but returns a data structure + This method is similar to createTwoFilesPatch, but returns a data structure suitable for further processing. Parameters are the same as createTwoFilesPatch. The data structure returned may look like this: ```js @@ -101,7 +101,7 @@ or This method will iterate over the contents of the patch and apply to data provided through callbacks. The general flow for each patch index is: - `options.loadFile(index, callback)` is called. The caller should then load the contents of the file and then pass that to the `callback(err, data)` callback. Passing an `err` will terminate further patch execution. - - `options.patched(index, content)` is called once the patch has been applied. `content` will be the return value frmo `applyPatch`. + - `options.patched(index, content)` is called once the patch has been applied. `content` will be the return value from `applyPatch`. Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made. @@ -115,7 +115,7 @@ or All methods above which accept the optional `callback` method will run in sync mode when that parameter is omitted and in async mode when supplied. This allows for larger diffs without blocking the event loop. This may be passed either directly as the final parameter or as the `callback` field in the `options` object. ### Change Objects -Many of the methods above return change objects. These objects are consist of the following fields: +Many of the methods above return change objects. These objects consist of the following fields: * `value`: Text content * `added`: True if the value was inserted into the new string diff --git a/components/bower.json b/components/bower.json index efdfba2c..7a8404b3 100644 --- a/components/bower.json +++ b/components/bower.json @@ -1,6 +1,6 @@ { "name": "jsdiff", - "version": "2.2.2", + "version": "2.2.3", "main": [ "diff.js" ], diff --git a/components/component.json b/components/component.json index ce9dd4e0..e90ac11d 100644 --- a/components/component.json +++ b/components/component.json @@ -6,7 +6,7 @@ "diff", "text" ], - "version": "2.2.2", + "version": "2.2.3", "scripts": [ "diff.js" ], "main": "diff.js", "license": "BSD" diff --git a/package.json b/package.json index 3194fcd0..f0466532 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "diff", - "version": "2.2.2", + "version": "2.2.3", "description": "A javascript text diff implementation.", "keywords": [ "diff", diff --git a/release-notes.md b/release-notes.md index 3172175c..9dfa3c0b 100644 --- a/release-notes.md +++ b/release-notes.md @@ -2,7 +2,14 @@ ## Development -[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.2...master) +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.3...master) + +## v2.2.3 - May 31st, 2016 +- [#118](https://github.com/kpdecker/jsdiff/pull/118) - Add a fix for applying 0-length destination patches ([@chaaz](https://api.github.com/users/chaaz)) +- [#115](https://github.com/kpdecker/jsdiff/pull/115) - Fixed grammar in README ([@krizalys](https://api.github.com/users/krizalys)) +- [#113](https://github.com/kpdecker/jsdiff/pull/113) - fix typo ([@vmazare](https://api.github.com/users/vmazare)) + +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.2...v2.2.3) ## v2.2.2 - March 13th, 2016 - [#102](https://github.com/kpdecker/jsdiff/issues/102) - diffJson with dates, returns empty curly braces ([@dr-dimitru](https://api.github.com/users/dr-dimitru)) diff --git a/src/patch/apply.js b/src/patch/apply.js index fda26ece..864d52da 100644 --- a/src/patch/apply.js +++ b/src/patch/apply.js @@ -81,6 +81,7 @@ export function applyPatch(source, uniDiff, options = {}) { for (let i = 0; i < hunks.length; i++) { let hunk = hunks[i], toPos = hunk.offset + hunk.newStart - 1; + if (hunk.newLines == 0) { toPos++; } for (let j = 0; j < hunk.lines.length; j++) { let line = hunk.lines[j], diff --git a/test/patch/apply.js b/test/patch/apply.js index dbf24277..3e278f61 100644 --- a/test/patch/apply.js +++ b/test/patch/apply.js @@ -416,6 +416,23 @@ describe('patch/apply', function() { + 'line5\n'); }); + it('should erase a file', function() { + expect(applyPatch( + 'line1\n' + + 'line2\n' + + 'line3\n' + + 'line4\n', + + '--- test\theader1\n' + + '+++ test\theader2\n' + + '@@ -1,4 +0,0 @@\n' + + '-line1\n' + + '-line2\n' + + '-line3\n' + + '-line4\n')) + .to.equal(''); + }); + it('should allow custom line comparison', function() { expect(applyPatch( 'line2\n'