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] Enable @ember/object#get to be called with an empty string #16870

Merged
merged 1 commit into from Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/ember-glimmer/tests/integration/syntax/each-in-test.js
Expand Up @@ -281,6 +281,22 @@ class EachInTest extends AbstractEachInTest {

this.assertText('Empty!');
}

[`@test it can render items with a key of empty string`]() {
this.makeHash({ '': 'empty-string', a: 'a' });

this.render(
`<ul>{{#each-in hash as |key value|}}<li>{{key}}: {{value}}</li>{{else}}Empty!{{/each-in}}</ul>`
);

this.assertText(': empty-stringa: a');

this.assertStableRerender();

this.clear();

this.assertText('Empty!');
}
}

moduleFor(
Expand Down
1 change: 0 additions & 1 deletion packages/ember-metal/lib/property_get.ts
Expand Up @@ -90,7 +90,6 @@ export function get(obj: object, keyName: string): any {
`'this' in paths is not supported`,
typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0
);
assert('Cannot call `get` with an empty string', keyName !== '');

let type = typeof obj;

Expand Down
15 changes: 14 additions & 1 deletion packages/ember-metal/tests/accessors/get_test.js
Expand Up @@ -59,6 +59,20 @@ moduleFor(
assert.equal(get(arr, 1), 'second');
}

['@test should retrieve an empty string key on an object'](assert) {
let obj = { '': 'empty-string' };

assert.equal(get(obj, ''), 'empty-string');
}

['@test should return undefined when passed an empty string if that key does not exist on an object'](
assert
) {
let obj = { tomster: true };

assert.equal(get(obj, ''), undefined);
}

['@test should not access a property more than once'](assert) {
let count = 0;
let obj = {
Expand Down Expand Up @@ -177,7 +191,6 @@ moduleFor(
() => get(obj, false),
/The key provided to get must be a string or number, you passed false/
);
expectAssertion(() => get(obj, ''), /Cannot call `get` with an empty string/);
}

// ..........................................................
Expand Down