binary-parser icon indicating copy to clipboard operation
binary-parser copied to clipboard

Choice keyString returns entire string

Open shaynem opened this issue 3 years ago • 1 comments

Choices seem to be broken in some instances, even though tag is int8

I have not fully tested, however I think it may have something to do with strict mode.

Working replacement

 Object.keys(options.choices).forEach(async (keyid) => {
            const key = parseInt(keyid, 10);
            const value = key
            if (isNaN(key)) {
                console.log(`Choice key "${keyid}" is not a number.`);
            }
            if (typeof value === "string" &&
                !aliasRegistry.has(value) &&
                !(value in PRIMITIVE_SIZES)) {
                throw new Error(`Choice type "${value}" is unkown.`);
            }
        })

keyString returns entire object, not just the index ID.

for (const keyString in options.choices) {
            const key = parseInt(keyString, 10);
            const value = options.choices[key];
            if (isNaN(key)) {
                throw new Error(`Choice key "${keyString}" is not a number.`);
            }
            if (typeof value === "string" &&
                !aliasRegistry.has(value) &&
                !(value in PRIMITIVE_SIZES)) {
                throw new Error(`Choice type "${value}" is unkown.`);
            }

shaynem avatar Jun 30 '22 12:06 shaynem

Could you describe how it's broken and provide a minimal reproducible example?

keichi avatar Jul 04 '22 05:07 keichi

Closing due to inactivity.

keichi avatar Sep 21 '22 04:09 keichi