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

Use Object.create(null) to avoid inherit properties like constructor #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sileix
Copy link

@sileix sileix commented Jun 29, 2021

Objects created from literal syntax will inherit properties from
Object.prototype, which includes constructor.
As a result, lexcon['constructor'] will return a function object
instead of undefined.

This bug was discovered while using en-pos, and can be reproduced by the following code:

const Tag = require("en-pos").Tag;
const tags = new Tag(["constructor"]).initial() .smooth().tags;

During initial(), it calls lexicon.ts where it assumes the return value of lexicon[token] is either undefined or string.

Object created from literal syntax will inherit properties from
`Object.prototype`, which includes `constructor`.
As a result, `lexcon['constructor']` will return a function object
instead of undefined.
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.

None yet

1 participant