Skip to content

Conversation

@bjohansebas
Copy link
Member

@bjohansebas bjohansebas commented Aug 10, 2025

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

Signed-off-by: Sebastian Beltran <[email protected]>
@bjohansebas bjohansebas self-assigned this Aug 10, 2025
@bjohansebas
Copy link
Member Author

Copy link
Contributor

@ashtuchkin ashtuchkin left a 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.
Copy link
Contributor

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.

Copy link
Member Author

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.

master branch:
imagen
imagen

This pr
imagen
imagen

@bjohansebas bjohansebas merged commit 89d04d2 into master Aug 16, 2025
35 checks passed
@bjohansebas bjohansebas deleted the prototype branch August 16, 2025 00:25
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.

Default Object keys result in false positives

2 participants