fix: case-insensitive decode for base16/base32/base36 (multibase spec)#341
Merged
Merged
Conversation
The multibase registry marks base16, base32 (and all 8 variants) and base36 as case-insensitive, and the spec's case_insensitivity.csv fixture requires their decoders to accept differently cased input "without errors". RFC 4648 section 3.4 backs this for base16/base32, and go-multibase decodes these codecs case-insensitively. Currently mixed-case input throws "Non-baseXX character". Thread a caseInsensitive flag from the rfc4648 and baseX factories so the decode lookup resolves both cases for only the spec-designated codecs. Encode output stays canonical and case-sensitive codecs are unaffected.
rvagg
approved these changes
Jun 24, 2026
rvagg
left a comment
Member
There was a problem hiding this comment.
yeah, legit, and matches go-multibase
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 24, 2026
## [14.0.1](v14.0.0...v14.0.1) (2026-06-24) ### Bug Fixes * case-insensitive decode for base16/base32/base36 (multibase spec) ([#341](#341)) ([ad87caa](ad87caa))
|
🎉 This PR is included in version 14.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The multibase registry marks several codecs as case-insensitive:
base16,base16upper,base32,base32upper,base32pad,base32padupper,base32hex,base32hexupper,base32hexpad,base32hexpadupper,base36,base36upper.The multibase spec test suite (
tests/README.md) describescase_insensitivity.csvas:On the current code these decoders throw on differently cased input. Every line below encodes
hello world(hex68656c6c6f20776f726c64):All 12 lines of the spec's
case_insensitivity.csvfail this way. The other three official fixtures (basic,leading_zero,two_leading_zeros) already pass, so this is purely the case-insensitivity gap. The repo's owntest/test-multibase-spec.spec.tscarries the basic fixtures inline but omitscase_insensitivity.csv, which hid the gap.This matters for interop: a multibase string produced by a case-insensitive-tolerant implementation (for example go-multibase output that was upper/lower-folded in transit) does not decode in JS today.
References
tests/case_insensitivity.csvfixture ("must decode without errors").README.mdregistry table marks these codecs case-insensitive.hex.DecodeString(case-insensitive) and base32 through case-insensitive decoders, andmultibase_test.gotampers case for case-insensitive codecs and requires decode to succeed.Fix
Thread an optional
caseInsensitiveflag from therfc4648andbaseXfactories. When set, the decode lookup table maps both the lower and upper case of each alphabet character to the same index. The flag is enabled only for the spec-designated codecs above.Scope notes:
base58btc,base58flickr,base64,base64url,base64pad,base256emoji,identity,base2,base8,base10) keep the defaultfalseand are unaffected.base32zis not in the case-insensitive registry and is left case-sensitive.Tests
Added a
case insensitivityblock totest/test-multibase-spec.spec.tsusing the exact 12 fixture strings from the spec'scase_insensitivity.csv, asserting each decodes tohello world. These tests fail onmasterand pass with this change. The full node suite is green (478 passing), encode output is byte-identical, and case-sensitive codecs still reject mixed case.