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

Fix empty object check in _renew() cookie session store #2263

Merged
merged 1 commit into from
Jan 28, 2021

Conversation

reidab
Copy link
Contributor

@reidab reidab commented Jan 28, 2021

The _renew implementation in the cookie session store includes a check for data !== {}.

While this deceptively looks like it's checking for an empty object, {} === {} is false in JavaScript so the check never resolved. This replaces that check with an alternative that correctly identifies empty objects.

@@ -287,7 +287,7 @@ export default BaseStore.extend({

_renew() {
return this.restore().then((data) => {
if (!isEmpty(data) && data !== {}) {
if (!isEmpty(data) && !(data.constructor === Object && Object.keys(data).length === 0)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why data !== {} was added at all since isEmpty should handle the case we're trying to prevent against here anyway?

Copy link
Contributor Author

@reidab reidab Jan 28, 2021

Choose a reason for hiding this comment

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

Also unintuitively, Ember's isEmpty doesn't check for empty objects: https://api.emberjs.com/ember/release/classes/@ember%2Futils/methods?anchor=isEmpty

isEmpty({});               // false

@marcoow marcoow merged commit b32ffed into mainmatter:master Jan 28, 2021
@sdebarros sdebarros added the bug label Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants