Add opt-in ignoreWhitespace decoding for Base-16/32/64#22
Closed
dipu-bd wants to merge 3 commits into
Closed
Conversation
Add an `ignoreWhitespace` parameter (default `false`) to `fromHex`, `fromBase32`, `fromBase64`, and their `tryFrom` counterparts. When `true`, ASCII whitespace (space, tab, line feed, vertical tab, form feed, carriage return) is skipped before decoding, so line-wrapped PEM/MIME payloads decode without pre-processing. The default path is unchanged and byte-identical. Stripping is done by a shared internal `stripWhitespace` helper that returns a plain `List<int>` so wide code units are preserved and cannot be truncated into valid characters. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015JBrb6sTw7442YbCzkxrxu
dipu-bd
force-pushed
the
claude/issue-20-ignore-whitespace
branch
from
July 22, 2026 18:37
d40c0a4 to
cd43ee3
Compare
Count whitespace in a first pass and return the input unchanged when there is none, so passing `ignoreWhitespace: true` over an unfolded payload copies nothing. When whitespace is present, allocate a single exactly-sized buffer instead of a full-length buffer followed by a `sublist`. Output is unchanged, and the buffer stays a plain `List<int>` so wide code units are not truncated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZrBRgz54K7qhuKKxebaxu
Instead of pre-stripping whitespace into an intermediate list, `fromBase32` and `fromBase64` now pass `ignoreWhitespace` straight to the decoder. The specialized decoders keep their fixed-group fast paths unchanged for the strict default and defer only the whitespace case to the generic `AlphabetDecoder` accumulator, which skips ASCII whitespace in a single pass with no intermediate buffer. Output is unchanged, and wide code units are still rejected rather than truncated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZrBRgz54K7qhuKKxebaxu
Member
Author
|
not good enough |
Codecov Report✅ All modified and coverable lines are covered by tests.
|
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.
Summary
Adds an opt-in
ignoreWhitespaceparameter (defaultfalse) to the public decode functions and their non-throwing counterparts:fromHex/tryFromHexfromBase32/tryFromBase32fromBase64/tryFromBase64When
true, ASCII whitespace (space,\t,\n,\v,\f,\r) in the input is skipped instead of rejected, so line-wrapped payloads such as PEM and MIME decode without pre-processing. The default isfalse, so existing decode behavior is unchanged and byte-identical.Design
Whitespace is stripped in the public functions via a shared internal helper,
lib/src/core/whitespace.dart, rather than by adding a field to the exportedAlphabetDecoder. Rationale:static constcodec instances (a decoder-level flag would need a relaxed twin of every Base-64/Base-32 variant).The helper returns a plain
List<int>(never aUint8List) so code units wider than a byte are preserved exactly and cannot be truncated into a valid character — guarding against the truncating-buffer failure mode.Tests
test/whitespace_test.dartcovers:stripWhitespacehelper: each of the six whitespace characters removed, wide-code-unit preservation (0x141survives, does not become'A'), no-whitespace passthrough, all-whitespace → empty, and near-whitespace controls left intact.dart:converton a 64-column CRLF-wrapped PEM-style block, a known-answer vector, roundtrips with injected whitespace at every length 0..99, strict-still-rejects, and non-whitespace-invalid-still-throws.tryFrom*honouring the flag.Checklist
dart format --output=none --set-exit-if-changed .— cleandart analyze --fatal-infos— No issues founddart test— 1359 pass on VM and Nodetest_integrationruns_next_), README recipe +example/whitespace_example.dartupdatedGenerated by Claude Code