Skip to content

Commit

Permalink
Fix array props support (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero committed Aug 29, 2017
1 parent b1d192a commit 5312d1d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
11 changes: 9 additions & 2 deletions dist/fast-json-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ var objOps = {
/* The operations applicable to an array. Many are the same as for the object */
var arrOps = {
add: function (arr, i, document) {
arr.splice(i, 0, this.value);
if (helpers_1.isInteger(i)) {
arr.splice(i, 0, this.value);
}
else {
arr[i] = this.value;
}
// this may be needed when using '-' in an array
return { newDocument: document, index: i };
},
Expand Down Expand Up @@ -441,8 +446,10 @@ function applyOperation(document, operation, validateOperation, mutateDocument)
else {
if (validateOperation && !helpers_1.isInteger(key)) {
throw new exports.JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", 0, operation.path, operation);
} // only parse key when it's an integer for `arr.prop` to work
else if (helpers_1.isInteger(key)) {
key = ~~key;
}
key = ~~key;
}
if (t >= len) {
if (validateOperation && operation.op === "add" && key > obj.length) {
Expand Down

0 comments on commit 5312d1d

Please sign in to comment.