Skip to content
Merged
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
24 changes: 24 additions & 0 deletions Jint.Tests/Runtime/RegExpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ public void ShouldSupportRegExpModifiersInLiteralsAndConstructor()
""").AsString().Should().Be("false,true");
}

[Fact]
public void ShouldAllowClassSetSyntaxCharacterOutsideClassSetForFlagV()
{
var engine = new Engine();
var result = engine.Evaluate(@"new RegExp('/-', 'v').test('/-')");
Assert.True(result.AsBoolean());
}

[Fact]
public void ShouldAllowClassSetReservedDoublePunctuatorCharactersOutsideClassSetForFlagV()
{
var engine = new Engine();
var result = engine.Evaluate(@"new RegExp('&&!!##%%,,::;;<<==>>@@``~~', 'v').test('&&!!##%%,,::;;<<==>>@@``~~')");
Assert.True(result.AsBoolean());
}

[Fact]
public void ShouldAllowEscapedClassSetReservedPunctuatorsForFlagV()
{
var engine = new Engine();
var result = engine.Evaluate(@"new RegExp('[\\!\\#\\%\\&\\,\\-\\:\\;\\<\\=\\>\\@\\`\\~]{14}', 'v').test('!#%&,-:;<=>@`~')");
Assert.True(result.AsBoolean());
}

[Fact]
public void Issue506()
{
Expand Down
15 changes: 12 additions & 3 deletions Jint/Runtime/RegExp/RegExpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,16 @@ private int GetClassAtom(REStringList? cr, bool inclass)
else
{
_pos = savedPos;
if (IsUnicode)
if (IsUnicode
&& (!UnicodeSets
|| !inclass
|| _pattern[_pos] is not
(
'!' or '#' or '%' or '&'
or ',' or '-' or ':' or ';'
or '<' or '=' or '>' or '@'
or '`' or '~'
)))
{
throw new RegExpSyntaxException("invalid escape sequence in regular expression");
}
Expand Down Expand Up @@ -1274,7 +1283,7 @@ private int GetClassAtom(REStringList? cr, bool inclass)
case '^':
case '`':
case '~':
if (UnicodeSets && _pos + 1 < _patternEnd && _pattern[_pos + 1] == c)
if (UnicodeSets && inclass && _pos + 1 < _patternEnd && _pattern[_pos + 1] == c)
{
// Forbidden double characters in unicode-sets mode
throw new RegExpSyntaxException("invalid class set operation in regular expression");
Expand All @@ -1290,7 +1299,7 @@ private int GetClassAtom(REStringList? cr, bool inclass)
case '/':
case '-':
case '|':
if (UnicodeSets)
if (UnicodeSets && inclass)
{
throw new RegExpSyntaxException("invalid character in class in regular expression");
}
Expand Down
Loading