Skip to content

Commit

Permalink
Issue with string shortcuts failing on primitives. (Issue andrewplumm…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewplummer committed Aug 3, 2018
1 parent 4c72a71 commit d440c78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ function deepSetProperty(obj, key, val) {

function handleDeepProperty(obj, key, any, has, fill, fillLast, val) {
var ns, bs, ps, cbi, set, isLast, isPush, isIndex, nextIsIndex, exists;
ns = obj || undefined;
ns = obj;
if (key == null) return;

if (isObjectType(key)) {
Expand Down Expand Up @@ -486,7 +486,9 @@ function handleDeepProperty(obj, key, any, has, fill, fillLast, val) {
// 2nd part, if there is only 1 part, or if there is an explicit key.
if (i || key || blen === 1) {

exists = any ? key in ns : hasOwn(ns, key);
// TODO: need to be sure this check handles ''.length when
// we refactor.
exists = any ? key in Object(ns) : hasOwn(ns, key);

// Non-existent namespaces are only filled if they are intermediate
// (not at the end) or explicitly filling the last.
Expand Down Expand Up @@ -886,7 +888,7 @@ function mapWithShortcuts(el, f, context, mapArgs) {
} else if (isFunction(el[f])) {
return el[f].call(el);
} else {
return deepGetProperty(el, f);
return deepGetProperty(el, f, true);
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/tests/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,7 @@ namespace('Array', function() {
});

method('max', function() {

test([12,87,55], 87, 'no argument');
test([12,87,55], oneUndefined, 87, 'undefined');
test([12,87,55], [null], 87, 'null');
Expand Down Expand Up @@ -1506,8 +1507,12 @@ namespace('Array', function() {
test(arr, ['a.b.c'], {id:1,a:{b:{c:6}}}, 'by deep dot operator');
test(arr, [true, 'a.b.c'], [{id:1,a:{b:{c:6}}},{id:2,a:{b:{c:6}}}], 'by deep dot operator multiple');

test(['one','two','three'], ['length'], 'three', 'Shold allow a string property');
test(['','two','three'], ['length'], 'three', 'Shold allow an empty string');

});


method('least', function() {

var fn, arr;
Expand Down

0 comments on commit d440c78

Please sign in to comment.