diff --git a/lib/clone.js b/lib/clone.js index 1b0f8bf..2c18fa3 100644 --- a/lib/clone.js +++ b/lib/clone.js @@ -14,6 +14,10 @@ function clone(x) { return x; } + if (x instanceof String || x instanceof Number || x instanceof Boolean) { + return x.valueOf(); + } + if(Array.isArray(x)) { return cloneArray(x); } diff --git a/test/jsonPatch-test.js b/test/jsonPatch-test.js index d4f798b..b0981e9 100644 --- a/test/jsonPatch-test.js +++ b/test/jsonPatch-test.js @@ -21,6 +21,24 @@ buster.testCase('jsonPatch', { assert.equals(result.value, 1); }, + 'should replace String': function() { + var a = { value: 0 }; + var result = jsonPatch.apply([{ op: 'add', path: '/value', value: new String("value") }], a); + assert.equals(result.value, "value"); + }, + + 'should replace Number': function() { + var a = { value: 0 }; + var result = jsonPatch.apply([{ op: 'add', path: '/value', value: new Number(1) }], a); + assert.equals(result.value, 1); + }, + + 'should replace Boolean': function() { + var a = { value: 0 }; + var result = jsonPatch.apply([{ op: 'add', path: '/value', value: new Boolean(true) }], a); + assert.equals(result.value, true); + }, + 'should throw': { 'when path is invalid': function() { assert.exception(function() {