-
Notifications
You must be signed in to change notification settings - Fork 293
fix: fix false positives in encodingExists #328
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
Conversation
Signed-off-by: Sebastian Beltran <[email protected]>
Signed-off-by: Sebastian Beltran <[email protected]>
Signed-off-by: Sebastian Beltran <[email protected]>
|
cc: @jonchurch @UlisesGascon @Phillip9587 btw this issue also affects body-parser. Without this change, the error thrown by body-parser is at https://github.com/expressjs/body-parser/blob/0dad12f03792ee4991d1054b1f5ff35ed70a3e34/lib/read.js#L124, whereas with this change it’s at https://github.com/expressjs/body-parser/blob/0dad12f03792ee4991d1054b1f5ff35ed70a3e34/lib/read.js#L66. It will always throw an error, but now in different place. |
ashtuchkin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| iconv.encodings = require("../encodings"); // Lazy load all encoding definitions. | ||
| if (!iconv.encodings) { | ||
| var raw = require("../encodings"); | ||
| iconv.encodings = objectAssign(Object.create(null), raw); // Lazy load all encoding definitions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one minor nit - I've tried my best to keep the set of dependencies minimal, not sure how important it is in today's standards. It seems that here it's a matter of a simple for loop to assign the properties. I'll leave it to you to make a decision of whether it's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I was looking at the past commits and issues. In this case, the bundler barely increases. In Webpack or other bundlers, depending on the ECMAScript version they are compiling, it might reduce more. However, in this case, we’re using Webpack in development mode, for production, it should reduce even more.


Since the object that holds the encodings has a prototype, it can cause false positives when searching for it internally. This also applies to the internal cache that this library has
The solution is to create an object with no prototype, with this change, when using encodingExists it will no longer return true for properties from the prototype.
Either way, iconv.decode or iconv.encode, when trying to access an encoding called 'constructor', would throw an error because they don’t have the necessary methods to perform the encoding transformation.
closes #323