Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release history of PerlOnJava. See [Roadmap](roadmap.md) for future plans.

- Fix localization of numbered regex captures.
- Fix IO-handle type checks and uninitialized-value warning locations.
- Fix Unicode regex interpolation in substitutions.
- Fix numeric-zero results from failed `s///` substitutions.
- Bundle the complete CPAN `File::Path` 2.18 implementation, including modern
`rmtree`/`remove_tree` options such as `keep_root`, `error`, `result`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ private static boolean isByteCompatiblePatternPart(RuntimeScalar scalar) {
}

static RuntimeScalar patternScalar(String pattern, boolean byteBackedPattern) {
return byteBackedPattern
// A byte-backed scalar cannot represent characters outside the Latin-1
// byte range. This matters when a Unicode qr// is stringified and
// embedded in an interpolated substitution.
boolean byteCompatible = byteBackedPattern
&& pattern.chars().allMatch(ch -> ch <= 0xFF);
return byteCompatible
? new RuntimeScalar(pattern.getBytes(StandardCharsets.ISO_8859_1))
: new RuntimeScalar(pattern);
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/unit/regex/unicode_qr_substitution_template.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use strict;
use warnings;
use utf8;
use Test::More tests => 2;

my $tld = qr/(?:com|みんな|中国|테스트|भारत|москва)/i;

my $text = "Visit site.みんな today";
$text =~ s{ (.*?) ($tld) | (.+?)$ }{defined $1 ? $1 : $3}gsex;
is($text, 'Visit site. today', 'substitution compiles an interpolated Unicode qr');

my $ascii = qr/(?:com|org)/i;
my $ascii_text = 'Visit site.com today';
$ascii_text =~ s{ (.*?) ($ascii) | (.+?)$ }{defined $1 ? $1 : $3}gsex;
is($ascii_text, 'Visit site. today', 'ASCII qr interpolation remains compatible');
Loading