Skip to content
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

Merged
merged 1 commit into from
May 6, 2016

Conversation

pittst3r
Copy link
Contributor

@pittst3r pittst3r commented May 4, 2016

Addresses issue #13444.

As is:

Ember.get({ foo: null }, 'foo.bar') === null

Expected:

Ember.get({ foo: null }, 'foo.bar') === undefined

This bug results in:

let o = Ember.Object.extend({ foo: null }).create();
o.get('foo.bar') || 'x' === 'x' 
o.getWithDefault('foo.bar', 'x') === null // wat

@pittst3r pittst3r changed the title [WIP BUGFIX] Ember.get with first part of path chain resolving to null results in null rather than undefined [WIP] [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined May 4, 2016
@krisselden
Copy link
Contributor

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');
Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Good catch!

@pittst3r pittst3r changed the title [WIP] [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined May 5, 2016
@pittst3r
Copy link
Contributor Author

pittst3r commented May 5, 2016

K, ready for review!

@pittst3r pittst3r changed the title [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined [WIP] [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined May 5, 2016
@pittst3r pittst3r changed the title [WIP] [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined May 5, 2016
@mmun
Copy link
Member

mmun commented May 5, 2016

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) {
Copy link
Contributor

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; }

Copy link
Contributor

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.

Copy link
Member

@mmun mmun May 5, 2016

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)

Copy link
Contributor

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.

@krisselden
Copy link
Contributor

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.

@pittst3r
Copy link
Contributor Author

pittst3r commented May 5, 2016

@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.

@krisselden
Copy link
Contributor

@robbiepitts at least in this PR reduce it to just a falsy check.

@rwjblue
Copy link
Member

rwjblue commented May 5, 2016

Seems like [BUGFIX beta] to me.

@krisselden krisselden changed the title [BUGFIX] Ember.get with first part of path chain resolving to null returns null rather than undefined [BUGFIX beta] Ember.get with first part of path chain resolving to null returns null rather than undefined May 6, 2016
@krisselden krisselden merged commit 82be117 into emberjs:master May 6, 2016
@mixonic
Copy link
Member

mixonic commented May 6, 2016

👍

rwjblue pushed a commit that referenced this pull request May 9, 2016
…`null` returns `null` rather than `undefined` (#13449)

(cherry picked from commit 82be117)
toddjordan pushed a commit to toddjordan/ember.js that referenced this pull request Sep 9, 2016
@rwjblue rwjblue mentioned this pull request Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants