Skip to content

Commit

Permalink
Changing 0 to empty string should create a patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mweathers committed Nov 17, 2016
1 parent 20ed496 commit a471f21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/json-patch-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ var jsonpatch;
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key));
}
else {
if (oldVal != newVal) {
if (oldVal !== newVal) {
changed = true;
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: deepClone(newVal) });
}
Expand Down
2 changes: 1 addition & 1 deletion src/json-patch-duplex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ module jsonpatch {
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key));
}
else {
if (oldVal != newVal) {
if (oldVal !== newVal) {
changed = true;
patches.push({op: "replace", path: path + "/" + escapePathComponent(key), value: deepClone(newVal)});
}
Expand Down
15 changes: 15 additions & 0 deletions test/spec/duplexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,21 @@ describe("duplex", function() {
value: null
}]);
});

it("should replace 0 with empty string", function () {
var objA = {
user: 0
};
var objB = {
user: ''
};

expect(jsonpatch.compare(objA, objB)).toReallyEqual([{
op: "replace",
path: "/user",
value: ''
}]);
});
});


Expand Down

0 comments on commit a471f21

Please sign in to comment.