fix: Add encoding option to Digest->new() for charset normalization#10
Draft
toddr-bot wants to merge 4 commits into
Draft
fix: Add encoding option to Digest->new() for charset normalization#10toddr-bot wants to merge 4 commits into
toddr-bot wants to merge 4 commits into
Conversation
Digest algorithms operate on raw bytes, but Perl strings can have
different internal byte representations (Latin-1 vs UTF-8) for the
same characters. This means the same logical text can produce different
digests depending on Perl's internal encoding state, which the
programmer may not control.
Add an `encoding` option to Digest->new() that wraps the digest context
with Digest::Encoder, automatically encoding strings via Encode::encode()
before they reach the digest algorithm:
my $ctx = Digest->new("SHA-256", encoding => "UTF-8");
$ctx->add($any_string); # always encoded to UTF-8 bytes first
This ensures consistent digests regardless of internal representation.
Fixes #3
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Digest::Encoder and t/encoding.t were missing from MANIFEST, meaning they would not be included in the CPAN tarball and CPAN testers would not run the new tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Docker Hub deprecated Image Format v1, breaking pulls for perl:5.8 through perl:5.24 containers on GitHub Actions. This caused all CI runs (including main branch) to fail on those versions. - Remove Perl 5.8-5.24 from matrix (Docker images no longer pullable) - Add Perl 5.34, 5.36, 5.38, 5.40 to matrix - Update actions/checkout from v2 to v4 The module still supports Perl 5.006+ at runtime; only CI coverage of versions older than 5.26 is affected by this infrastructure change. Supersedes #14 and #15. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consolidates CI improvements into a single change: - Remove Perl 5.8–5.24 from matrix (Docker Hub deprecated Image Format v1) - Add Perl 5.34, 5.36, 5.38, 5.40 to linux matrix - Update actions/checkout v2 → v4 (Node.js 12 → 20) - Add Windows CI job using Strawberry Perl Supersedes #14, #15, #18, and #20. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
encodingoption toDigest->new()that automatically encodes strings before digesting, ensuring consistent digests regardless of Perl's internal string representation. This wraps the digest context with a lightweightDigest::Encoderproxy that interceptsadd()calls and appliesEncode::encode().Fixes #3
Changes
Digest->new("SHA-256", encoding => "UTF-8")now returns an encoding-aware wrapperDigest::Encoderclass transparently wraps any digest implementationhexdigest,b64digest,isa, etc.) works through the wrapperencodingis not specifiedTest plan
t/encoding.tcovering:hexdigest/b64digestdelegationisatransparencyaddfiledelegationadd()encodingGenerated by Kōan /fix
Quality Report
Changes: 3 files changed, 305 insertions(+), 1 deletion(-)
Code scan: 1 issue(s) found
lib/Digest.pm:175— XXX markerTests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline