Skip to content

Commit

Permalink
Merge pull request dotnet#33310 from jasonmalinowski/fix-virtualchar-…
Browse files Browse the repository at this point in the history
…crash

Ensure we don't run off the end of the string when parsing \x1
  • Loading branch information
jasonmalinowski authored Feb 13, 2019
2 parents 25f0c8f + c5edbf0 commit a516280
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ private bool TryAddMultiCharacterEscape(
return false;
}

var endIndex = index + 1;
for (var i = 0; i < 4; i++)
{
var ch2 = tokenText[index + i];
Expand All @@ -272,7 +271,6 @@ private bool TryAddMultiCharacterEscape(
}

intChar = (intChar << 4) + HexValue(ch2);
endIndex++;
}

character = (char)intChar;
Expand All @@ -292,7 +290,7 @@ private bool TryAddMultiCharacterEscape(
}

var endIndex = index;
for (var i = 0; i < 4; i++)
for (var i = 0; i < 4 && endIndex < tokenText.Length; i++)
{
var ch2 = tokenText[index + i];
if (!IsHexDigit(ch2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,10 @@ public void TestBracesInInterpolatedVerbatimSimpleString()
Test("$@\"{{\"", "['{',[3,5]]");
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/29172")]
public void TestReverseInterpolatedVerbatimString()
[Fact]
public void TestBracesInReverseInterpolatedVerbatimSimpleString()
{
// This will need to be fixed once @$ strings come online.
// This is tracked with https://github.com/dotnet/roslyn/issues/29172
var token = GetStringToken("@$\"{{\"", allowFailure: true);
Assert.True(token == default);

TestFailure("@$\"{{\"");
Test("@$\"{{\"", "['{',[3,5]]");
}

[Fact]
Expand Down Expand Up @@ -165,6 +160,12 @@ public void TestValidHex1Escape()
Test(@"""\xa""", @"['\u000A',[1,4]]");
}

[Fact]
public void TestValidHex1EscapeInInterpolatedString()
{
Test(@"$""\xa""", @"['\u000A',[2,5]]");
}

[Fact]
public void TestValidHex2Escape()
{
Expand Down

0 comments on commit a516280

Please sign in to comment.