Skip to content

fix: jcpan -t HTTP::Response::Encoding#595

Merged
fglock merged 2 commits intomasterfrom
fix/http-response-encoding-mime-name
Apr 28, 2026
Merged

fix: jcpan -t HTTP::Response::Encoding#595
fglock merged 2 commits intomasterfrom
fix/http-response-encoding-mime-name

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 28, 2026

Summary

Investigate and fix jcpan -t HTTP::Response::Encoding.

The test failed with:

Can't locate object method "mime_name" via package "Encode::Encoding"
   at /Users/fglock/.perlonjava/lib/HTTP/Message.pm line 254.

HTTP::Message::content_charset calls IO::HTML::find_charset_in(..., {encoding=>1}), which returns an Encode::Encoding object obtained from Encode::find_encoding. PerlOnJava blesses these objects into Encode::Encoding but only registered encode, decode, and name methods on that package — mime_name was missing.

A second failure, expected 'ascii', got 'US-ASCII', came from $enc->name returning the Java canonical charset name. Real Perl Encode returns its own canonical names (e.g. ascii, utf-8-strict).

Changes

  • Register Encode::Encoding::mime_name.
  • Store both a Perl-canonical Name and an IANA MimeName on the blessed encoding hash created by find_encoding.
  • name() returns the Perl-canonical name; mime_name() returns the IANA name (falling back to Name).

Test plan

  • make (full unit test suite passes)
  • ./jcpan -t HTTP::Response::EncodingResult: PASS, 18/18 subtests

Generated with Devin

fglock and others added 2 commits April 28, 2026 18:34
Add Encode::Encoding mime_name() and a Perl-canonical Name mapping so
HTTP::Message->content_charset (via IO::HTML::find_charset_in) and
$res->encoding work for ASCII/UTF-8 the way real Perl Encode behaves.

- Register Encode::Encoding::mime_name in the runtime.
- Store separate Name (Perl-canonical, e.g. "ascii", "utf-8-strict")
  and MimeName (IANA, e.g. "US-ASCII", "UTF-8") on the blessed object.
- mime_name() returns MimeName (falling back to Name); name() returns
  Name unchanged.

Result: jcpan -t HTTP::Response::Encoding now passes 18/18.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Java 21's Pattern.namedGroups() returns an ImmutableCollections.MapN
which does not preserve insertion order. HashSpecialVariable was
iterating that map's keySet() to group duplicate-named captures
(e.g. (?<bar>a)(?<bar>b)), so the order in which alternatives were
seen was effectively random — making `values %+` return the rightmost
capture instead of Perl's leftmost.

Sort each per-Perl-name list by group number (= source order) in both
entrySet() and collectJavaNamesFor(). This restores the 3 regressed
re/pat_advanced.t subtests (1317, 1320, 1321 in the "Test keys in %+
and %-" block) without affecting any other behavior.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit b7808a7 into master Apr 28, 2026
2 checks passed
@fglock fglock deleted the fix/http-response-encoding-mime-name branch April 28, 2026 18:34
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.

1 participant