2
Vote

index out of range in StringLiteral.cs

description

Hi I was getting an error so took a look at the source code and found this section of code on line 349 of StringLiteral.cs that is causing an index out of range exception.

if (segment.Length < len + 1) {
   details.Error = string.Format(Resources.ErrBadUnEscape, segment.Substring(len + 1), len);// "Invalid unicode escape ({0}), expected {1} hex digits."
   return segment;
}
You check segment.Length but accidently set Substring out of range.

comments

bernhof wrote Dec 9, 2014 at 3:36 PM

Proposed fix:

Change segment.Substring(...) to details.Text:
details.Error = string.Format(Resources.ErrBadUnEscape, details.Text, len);// "Invalid unicode escape ({0}), expected {1} hex digits."

bernhof wrote Dec 9, 2014 at 3:40 PM

... which would make the expression "\u1" to yield the following parser error:
Invalid unicode escape (\u1), expected 4 hex digits.