-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX beta] Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
#13449
Conversation
Ember.get
with first part of path chain resolving to null
results in null
rather than undefined
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
Good catch |
@@ -129,8 +129,8 @@ QUnit.test('should return null when property value is null on Ember.Observable', | |||
}); | |||
|
|||
QUnit.test('should call unknownProperty when value is undefined on Ember.Observable', function() { | |||
equal(get(object, 'unknown'), 'unknown'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would fail if only the Ember.get()
module was run and relied on the object.get()
module being run first to pass—for obvious reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. Good catch!
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
K, ready for review! |
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
… `null` rather than `undefined`
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
Looks good! @rwjblue @krisselden Does this need a canary cycle or can we put it into beta? |
@@ -76,7 +76,7 @@ export function _getPath(root, path) { | |||
|
|||
for (let i = 0; i < parts.length; i++) { | |||
if (obj == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only want to call get on object like things, this should do if (!isObjectLike(obj)) { return undefined; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be specific, I would check falsy, and that the typeof was 'string', 'object', 'function' but at a minimum this can simply check falsy. I'm sure the obj == null
check was a bad fix to this sometimes returning false vs undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falsey alone won't work because of empty strings, e.g.
Ember.get({ foo: "" }, 'foo.length')
should be 0 not undefined. (Can you add a test for this one @robbiepitts? if there isn't one already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirm, using get for string.length seems super lame.
This change is low risk. I think it is bad that we let random truthy values get to get() that aren't gettable too, not just that we return null sometimes. |
@krisselden Agreed. Would you like that addressed in this PR? Alternatively I can create an issue and work on it as a separate thing. Glad to do either. |
@robbiepitts at least in this PR reduce it to just a falsy check. |
Seems like |
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
Ember.get
with first part of path chain resolving to null
returns null
rather than undefined
👍 |
…`null` returns `null` rather than `undefined` (emberjs#13449)
Addresses issue #13444.
As is:
Expected:
This bug results in: