Skip to content

fix: Consistently handle scalar map keys#2186

Merged
dcodeIO merged 3 commits into
masterfrom
patch/map-key-conformance
Apr 28, 2026
Merged

fix: Consistently handle scalar map keys#2186
dcodeIO merged 3 commits into
masterfrom
patch/map-key-conformance

Conversation

@dcodeIO
Copy link
Copy Markdown
Member

@dcodeIO dcodeIO commented Apr 28, 2026

Fixes encoding and object conversion of scalar map keys that are stored internally as strings, enabling round-tripping of boolean and 64-bit map keys.

Also fixes the 64-bit map key check to accept the documented internal format.

Fixes #1203
Fixes #1652
Fixes #2087

Supersedes #1653
Supersedes #1669

Comment thread src/util/minimal.js
* @returns {boolean} Boolean value
*/
util.boolFromKey = function boolFromKey(key) {
return key === "true" || key === "1";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe even true if Number.isInteger(key) and it's not zero?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Here, keys are always strings, so Number.isInteger("2") would be false unless we convert first. Since this currently lines up with util.key2Re = /^true|false|0|1$/;, I’d lean toward keeping it analogous for now.

@dcodeIO
Copy link
Copy Markdown
Member Author

dcodeIO commented Apr 28, 2026

Note: this will once more need a follow-up protobufjs-cli peer dependency bump after the next protobufjs release due to the new $util.longFromKey / $util.boolFromKey helpers.

@dcodeIO dcodeIO merged commit 29b1183 into master Apr 28, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 28, 2026
@dcodeIO dcodeIO deleted the patch/map-key-conformance branch April 29, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants