Skip to content

Commit

Permalink
Issue #20. We are now escaping all quotes in the JSON strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrossbart committed Sep 12, 2018
1 parent eeeafe3 commit 291b45e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions jdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions jdd_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<a href=\\\"http://google.com/\\\">Google</a>"}');
$('#textarearight').val('{"link": "<a href=\\\"http://googlex.com/\\\">Google</a>"}');

jdd.compare();
assert.ok(jdd.diffs[0].type === jdd.EQUALITY, 'Checking correct type');
assert.ok($('pre.right div.line2 span').text().trim() === '"link": "<a href=\\\"http://googlex.com/\\\">Google</a>"', 'Checking escaped quotes');
assert.ok($('pre.left div.line2 span').text().trim() === '"link": "<a href=\\\"http://google.com/\\\">Google</a>"', 'Checking escaped quotes');

$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});


QUnit.done(function () {
$('div.initContainer').hide();
Expand Down

0 comments on commit 291b45e

Please sign in to comment.