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] Ignore enumerable Object.prototype extensions #4953

Merged
merged 4 commits into from Apr 24, 2020

Conversation

ashsearle
Copy link
Contributor

Several moment methods break if the Object.prototype has any additional enumerable properties.

moment().fromNow(); // "a few seconds ago"
Object.prototype.breakIt = true;
moment().fromNow(); // "Invalid date"

This is fixed by patching a few for (prop in object) loops so they only act on the object's own properties (using hasOwnProperty.)

Fixes #4802

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.007%) to 88.393% when pulling 03b5dd9 on ashsearle:fix/4802 into 0aae724 on moment:develop.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.007%) to 88.393% when pulling 03b5dd9 on ashsearle:fix/4802 into 0aae724 on moment:develop.

@coveralls
Copy link

coveralls commented Jan 22, 2019

Coverage Status

Coverage decreased (-0.007%) to 88.43% when pulling 21e7522 on ashsearle:fix/4802 into c1177f4 on moment:develop.

@mouse0270
Copy link

Is there any update on this pull request. It would be nice to use Object.prototype. without momentjs breaking.

@ashsearle
Copy link
Contributor Author

@mouse0270 You can still add things to Object.prototype without breaking moment; you just need to make sure they're not enumerable. i.e. use Object.defineProperty

@ichernev
Copy link
Contributor

@ashsearle thank you for the good work!

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.

moment().fromNow() returns 'Invalid date'
4 participants