Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.

Commit fa6ecc7

Browse files
committed
Merge pull request #22 from sdepold/hotfix/input-path-modification
Fix modification if path input variable
2 parents e16ce9f + 0a33c07 commit fa6ecc7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

dottie.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
}
2525
};
2626

27+
var reverseDupArray = function (array) {
28+
var result = new Array(array.length);
29+
var index = array.length;
30+
var arrayMaxIndex = index - 1;
31+
32+
while (index--) {
33+
result[arrayMaxIndex - index] = array[index];
34+
}
35+
36+
return result;
37+
};
38+
2739
var Dottie = function() {
2840
var args = Array.prototype.slice.call(arguments);
2941

@@ -60,7 +72,7 @@
6072
names = path.split('.').reverse();
6173
}
6274
} else if (Array.isArray(path)) {
63-
names = path.reverse();
75+
names = reverseDupArray(path);
6476
}
6577

6678
while (names.length && (object = object[names.pop()]) !== undefined && object !== null);

test/get.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ describe("dottie.get", function () {
9595
});
9696

9797
it('should get nested values with keys that have dots', function () {
98-
expect(dottie.get(data, ['nested.dot', 'key'])).to.equal('value');
98+
var path = ['nested.dot', 'key'];
99+
100+
expect(dottie.get(data, path)).to.equal('value');
101+
expect(path).to.eql(['nested.dot', 'key']);
99102
});
100103
});
101104
});

0 commit comments

Comments
 (0)