diff --git a/release-notes.md b/release-notes.md index 581d6349..49d335a5 100644 --- a/release-notes.md +++ b/release-notes.md @@ -13,6 +13,7 @@ - [#601](https://github.com/kpdecker/jsdiff/pull/601) - **`diffJson`'s `stringifyReplacer` option behaves more like `JSON.stringify`'s `replacer` argument now.** In particular: * Each key/value pair now gets passed through the replacer once instead of twice * The `key` passed to the replacer when the top-level object is passed in as `value` is now `""` (previously, was `undefined`), and the `key` passed with an array element is the array index as a string, like `"0"` or `"1"` (previously was whatever the key for the entire array was). Both the new behaviours match that of `JSON.stringify`. +- [#602](https://github.com/kpdecker/jsdiff/pull/602) - **diffing functions now consistently return `undefined` when called in async mode** (i.e. with a callback). Previously, there was an odd quirk where they would return `true` if the strings being diffed were equal and `undefined` otherwise. ## 7.0.0 diff --git a/src/diff/base.js b/src/diff/base.js index d58b5797..e54ea5a7 100644 --- a/src/diff/base.js +++ b/src/diff/base.js @@ -14,7 +14,7 @@ Diff.prototype = { value = self.postProcess(value, options); if (callback) { setTimeout(function() { callback(value); }, 0); - return true; + return undefined; } else { return value; } @@ -106,7 +106,7 @@ Diff.prototype = { if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) { // If we have hit the end of both strings, then we are done - return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken)); + return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken)) || true; } else { bestPath[diagonalPath] = basePath; if (basePath.oldPos + 1 >= oldLen) { diff --git a/test/diff/character.js b/test/diff/character.js index 4a731825..e3aef9a8 100644 --- a/test/diff/character.js +++ b/test/diff/character.js @@ -59,5 +59,10 @@ describe('diff/character', function() { diffChars('whatever', 'whatever', {ignoreCase: true}); diffChars('whatever', 'whatever', {ignoreCase: true, callback: () => {}}); }); + + it('should return undefined when called in async mode', function() { + expect(diffChars('whatever', 'whatever', {callback: () => {}})).to.be.undefined; + expect(diffChars('whatever', 'whatever else', {callback: () => {}})).to.be.undefined; + }); }); });