Skip to content

Commit 8013acd

Browse files
committed
Forbid synthetics as charrange endpoints.
Which in turn makes it fine that it works in terms of codepoints.
1 parent 517c8f8 commit 8013acd

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/QRegex/P6Regex/Actions.nqp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,27 +679,40 @@ class QRegex::P6Regex::Actions is HLL::Actions {
679679
my $node;
680680
my $ord0;
681681
my $ord1;
682+
sub non_synth_ord($chr) {
683+
my int $ord := nqp::ord($chr);
684+
if nqp::chr($ord) ne $chr {
685+
$/.CURSOR.panic("Cannot use $chr as a range endpoint, as it is not a single codepoint");
686+
}
687+
$ord
688+
}
682689
if $_[0]<cclass_backslash> {
683690
$node := $_[0]<cclass_backslash>.ast;
684691
$/.CURSOR.panic("Illegal range endpoint in regex: " ~ ~$_)
685692
if $node.rxtype ne 'literal' && $node.rxtype ne 'enumcharlist'
686693
|| $node.negate || nqp::chars($node[0]) != 1;
687-
$ord0 := $node.ann('codepoint') // nqp::ord($node[0]);
688-
$ord0 := nqp::ordbaseat(nqp::chr($ord0), 0) if $RXm;
694+
$ord0 := $node.ann('codepoint') // ($RXm
695+
?? nqp::ordbaseat($node[0], 0)
696+
!! non_synth_ord($node[0]));
689697
}
690698
else {
691-
$ord0 := $RXm ?? nqp::ordbaseat(~$_[0][0], 0) !! nqp::ord(~$_[0][0]);
699+
$ord0 := $RXm
700+
?? nqp::ordbaseat(~$_[0][0], 0)
701+
!! non_synth_ord(~$_[0][0]);
692702
}
693703
if $_[1][0]<cclass_backslash> {
694704
$node := $_[1][0]<cclass_backslash>.ast;
695705
$/.CURSOR.panic("Illegal range endpoint in regex: " ~ ~$_)
696706
if $node.rxtype ne 'literal' && $node.rxtype ne 'enumcharlist'
697707
|| $node.negate || nqp::chars($node[0]) != 1;
698-
$ord1 := $node.ann('codepoint') // nqp::ord($node[0]);
699-
$ord1 := nqp::ordbaseat(nqp::chr($ord1), 0) if $RXm;
708+
$ord1 := $node.ann('codepoint') // ($RXm
709+
?? nqp::ordbaseat($node[0], 0)
710+
!! non_synth_ord($node[0]));
700711
}
701712
else {
702-
$ord1 := $RXm ?? nqp::ordbaseat(~$_[1][0][0], 0) !! nqp::ord(~$_[1][0][0]);
713+
$ord1 := $RXm
714+
?? nqp::ordbaseat(~$_[1][0][0], 0)
715+
!! non_synth_ord(~$_[1][0][0]);
703716
}
704717
$/.CURSOR.panic("Illegal reversed character range in regex: " ~ ~$_)
705718
if $ord0 > $ord1;

0 commit comments

Comments
 (0)