diff --git a/jdd.js b/jdd.js index 3415b68..efe00b9 100644 --- a/jdd.js +++ b/jdd.js @@ -449,12 +449,12 @@ var jdd = { unescapeString: function (val) { if (val) { return val.replace('\\', '\\\\') // Single slashes need to be replaced first - .replace('\"', '\\"') // Then double quotes - .replace('\n', '\\n') // New lines - .replace('\b', '\\b') // Backspace - .replace('\f', '\\f') // Formfeed - .replace('\r', '\\r') // Carriage return - .replace('\t', '\\t'); // Horizontal tabs + .replace(/\"/g, '\\"') // Then double quotes + .replace(/\n/g, '\\n') // New lines + .replace('\b', '\\b') // Backspace + .replace(/\f/g, '\\f') // Formfeed + .replace(/\r/g, '\\r') // Carriage return + .replace(/\t/g, '\\t'); // Horizontal tabs } else { return val; } diff --git a/jdd_test.js b/jdd_test.js index b13af28..a8db01a 100644 --- a/jdd_test.js +++ b/jdd_test.js @@ -241,6 +241,20 @@ QUnit.test('Null object length tests - left side', function (assert) { jdd.setupNewDiff(); }); +QUnit.test('Escaped quotes test', function (assert) { + $('#textarealeft').val('{"link": "Google"}'); + $('#textarearight').val('{"link": "Google"}'); + + jdd.compare(); + assert.ok(jdd.diffs[0].type === jdd.EQUALITY, 'Checking correct type'); + assert.ok($('pre.right div.line2 span').text().trim() === '"link": "Google"', 'Checking escaped quotes'); + assert.ok($('pre.left div.line2 span').text().trim() === '"link": "Google"', 'Checking escaped quotes'); + + $('#textarealeft').val(''); + $('#textarearight').val(''); + jdd.setupNewDiff(); +}); + QUnit.done(function () { $('div.initContainer').hide();