Skip to content

Commit 77c9884

Browse files
committed
Detect repeat chars in character classes
1 parent ec3d853 commit 77c9884

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

STD.pm6

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5249,6 +5249,21 @@ grammar Regex is STD {
52495249
:dba('character class element')
52505250
"[" ~ "]" <nibble($¢.cursor_fresh( %*LANG<Q> ).tweak(:cc).unbalanced("]"))>
52515251
<.normspace>?
5252+
{
5253+
$_ = $<nibble>.Str;
5254+
1 while s/\s+|\.\.|\\//;
5255+
5256+
# XXX emulate /(.) .*? $0/ which viv flubs
5257+
my %seen;
5258+
for unpack('C*', $_) {
5259+
%seen{$_}++;
5260+
}
5261+
for keys %seen {
5262+
next if %seen{$_} < 2;
5263+
my $c = chr($_);
5264+
.worry("Repeated character ($c) unexpectedly found in character class");
5265+
}
5266+
}
52525267
}
52535268

52545269
token cclass_elem:sym<( )> {

0 commit comments

Comments
 (0)