diff-match-patch icon indicating copy to clipboard operation
diff-match-patch copied to clipboard

patch_toText, unified diff like output

Open mariusk opened this issue 6 years ago • 0 comments

The docs says this method should create something that looks like a unified diff. When I try it I just get "[object ...]" blah blah output. Looking at the actual source code for the method, it doesn't do much, it simply tries to output some of the objects in the diff. Here's the actual source code:

/**
 * Take a list of patches and return a textual representation.
 * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
 * @return {string} Text representation of patches.
 */
diff_match_patch.prototype.patch_toText = function(patches) {
  var text = [];
  for (var x = 0; x < patches.length; x++) {
    text[x] = patches[x];
  }
  return text.join('');
};

So patches[x] is a javascript object, and the text.join method just creates these faulty "object" strings. I can't find any code that does anything like the comments in the source code mentions. So I guess either we need some more code or the docs should be updated and mark this method as faulty.

mariusk avatar Mar 09 '18 11:03 mariusk