Skip to content

fix: normalize no longer throws on tokens such as "constructor" - #803

Open
OsamaAnsar wants to merge 1 commit into
NaturalNode:masterfrom
OsamaAnsar:fix/normalize-prototype-words
Open

OsamaAnsar wants to merge 1 commit into
NaturalNode:masterfrom
OsamaAnsar:fix/normalize-prototype-words

Conversation

@OsamaAnsar

Copy link
Copy Markdown
Contributor

normalize throws when a token is the name of a property that every object inherits:

const { normalize } = require('natural')

normalize(['the', 'constructor', "isn't", 'called'])
// TypeError: conversionTable[token.toLowerCase(...)].split is not a function

The conversion table is a plain object and is read with conversionTable[token.toLowerCase()]. For constructor that finds Object.prototype.constructor, which is truthy and has no split. __proto__ fails the same way.

The change only accepts the table's own keys. One new spec covers constructor, Constructor, __proto__ and the string form; it fails without the change. npm test (899 specs) and npm run lint pass.

The conversion table was read with a plain property lookup, so a token that
is the name of an inherited object property (constructor, __proto__) found
that property instead of a conversion and the call to split threw a
TypeError.

This branch has not been deployed

No deployments
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.

1 participant