Skip to content

Commit 19fc4f1

Browse files
committed
Fix punycode roundtrip bug (closes #2287)
1 parent 4dae171 commit 19fc4f1

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

Changes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
9.43 2025-10-02
2+
9.43 2026-02-12
3+
- Fixed punycode roundtrip bug in Mojo::Util.
34

45
9.42 2025-10-01
56
- Un-deprecated the spurt method in Mojo::File, it is now an alternative to spew.

lib/Mojo/Util.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ sub punycode_encode {
303303
my $h = my $basic = length $output;
304304
$output .= "\x2d" if $basic > 0;
305305

306-
for my $m (sort grep { $_ >= PC_INITIAL_N } @input) {
306+
for my $m (sort { $a <=> $b } grep { $_ >= PC_INITIAL_N } @input) {
307307
next if $m < $n;
308308
$delta += ($m - $n) * ($h + 1);
309309
$n = $m;

t/mojo/util.t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ subtest 'punycode_decode' => sub {
289289
is punycode_decode('bcher-kva'), 'bücher', 'right punycode decoded result';
290290
};
291291

292+
subtest 'punycode_decode/punycode_encode roundtrip' => sub {
293+
is punycode_decode(punycode_encode('☃⭐️ ')), '☃⭐️ ', 'right punycode roundtrip result';
294+
is punycode_decode(punycode_encode('🐳')), '🐳', 'right punycode roundtrip result';
295+
};
296+
292297
subtest 'RFC 3492' => sub {
293298
my @tests = (
294299
'(A) Arabic (Egyptian):',

0 commit comments

Comments
 (0)