Skip to content

internal/format: return correct byte count from writeWrapped#698

Merged
FiloSottile merged 2 commits intoFiloSottile:mainfrom
sweis:claude/fix-wrapped-base64-return-HXoHp
Mar 20, 2026
Merged

internal/format: return correct byte count from writeWrapped#698
FiloSottile merged 2 commits intoFiloSottile:mainfrom
sweis:claude/fix-wrapped-base64-return-HXoHp

Conversation

@sweis
Copy link
Contributor

@sweis sweis commented Mar 12, 2026

writeWrapped slices its argument p down to zero in a loop, then returns
len(p) — always (0, nil) on success. This violates the io.Writer contract.
Harmless today because encoding/base64 ignores the count, but
WrappedBase64Encoder / WriterFunc are exported.

Fix: save the original length before the loop.

Test: go test ./internal/format/ -run TestWriteWrappedReturnsCorrectLength -v

@sweis sweis closed this Mar 19, 2026
@sweis sweis reopened this Mar 19, 2026
@FiloSottile FiloSottile merged commit 4c86929 into FiloSottile:main Mar 20, 2026
18 checks passed
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.

3 participants