Skip to content

Commit

Permalink
Fix yet one bug related to nilproject#80
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Feb 1, 2018
1 parent be83def commit aaee503
Show file tree
Hide file tree
Showing 3 changed files with 99,602 additions and 130 deletions.
2 changes: 1 addition & 1 deletion FunctionalTests/Bug_106.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void SetField91()
}
Assert.IsTrue(pass); // failed

string json = JSON.stringify(ro, null, null); // json = {"-1":-1,"test":false}
string json = JSON.stringify(ro, null, null, null); // json = {"-1":-1,"test":false}
}

/// <summary>change field in immutable object</summary>
Expand Down
258 changes: 129 additions & 129 deletions NiL.JS/Core/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,175 +1336,175 @@ public static string Unescape(string code, bool strict, bool processUnknown, boo
{
case 'x':
case 'u':
{
if (i + (code[i] == 'u' ? 5 : 3) > code.Length)
{
if (i + (code[i] == 'u' ? 5 : 3) > code.Length)
if (processRegexComp)
{
if (processRegexComp)
{
res.Append(code[i]);
break;
}
else
ExceptionHelper.ThrowSyntaxError("Invalid escape code (\"" + code + "\")");
res.Append(code[i]);
break;
}
else
ExceptionHelper.ThrowSyntaxError("Invalid escape code (\"" + code + "\")");
}

if (fullUnicode && code[i] == 'u' && code[i + 1] == '{')
{
// look here in section 3.7 Surrogates for more information.
// http://unicode.org/versions/Unicode3.0.0/ch03.pdf
if (fullUnicode && code[i] == 'u' && code[i + 1] == '{')
{
// look here in section 3.7 Surrogates for more information.
// http://unicode.org/versions/Unicode3.0.0/ch03.pdf

int closingBracket = code.IndexOf('}', i + 2);
if (closingBracket == -1)
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence"));
int closingBracket = code.IndexOf('}', i + 2);
if (closingBracket == -1)
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence"));

string c = code.Substring(i + 2, closingBracket - i - 2);
uint ucs = 0;
if (uint.TryParse(c, NumberStyles.HexNumber, null, out ucs))
string c = code.Substring(i + 2, closingBracket - i - 2);
uint ucs = 0;
if (uint.TryParse(c, NumberStyles.HexNumber, null, out ucs))
{
if (ucs <= 0xFFFF)
res.Append((char)ucs);
else if (ucs <= 0x10FFFF)
{
if (ucs <= 0xFFFF)
res.Append((char)ucs);
else if (ucs <= 0x10FFFF)
{
ucs -= 0x10000;
char h = (char)((ucs >> 10) + 0xD800);
char l = (char)((ucs % 0x400) + 0xDC00);
res.Append(h).Append(l);
}
else
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence '\\u{" + c + "}'"));
i += c.Length + 2;
ucs -= 0x10000;
char h = (char)((ucs >> 10) + 0xD800);
char l = (char)((ucs % 0x400) + 0xDC00);
res.Append(h).Append(l);
}
else
{
if (processRegexComp)
res.Append(code[i]);
else
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence '\\u{" + c + "}'"));
}
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence '\\u{" + c + "}'"));
i += c.Length + 2;
}
else
{
string c = code.Substring(i + 1, code[i] == 'u' ? 4 : 2);
ushort chc = 0;
if (ushort.TryParse(c, NumberStyles.HexNumber, null, out chc))
{
char ch = (char)chc;
res.Append(ch);
i += c.Length;
}
if (processRegexComp)
res.Append(code[i]);
else
{
if (processRegexComp)
res.Append(code[i]);
else
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence '\\" + code[i] + c + "'"));
}
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence '\\u{" + c + "}'"));
}

break;
}
case 't':
else
{
res.Append(processRegexComp ? "\\t" : "\t");
break;
string c = code.Substring(i + 1, code[i] == 'u' ? 4 : 2);
ushort chc = 0;
if (ushort.TryParse(c, NumberStyles.HexNumber, null, out chc))
{
char ch = (char)chc;
res.Append(ch);
i += c.Length;
}
else
{
if (processRegexComp)
res.Append(code[i]);
else
ExceptionHelper.Throw(new SyntaxError("Invalid escape sequence '\\" + code[i] + c + "'"));
}
}

break;
}
case 't':
{
res.Append(processRegexComp ? "\\t" : "\t");
break;
}
case 'f':
{
res.Append(processRegexComp ? "\\f" : "\f");
break;
}
{
res.Append(processRegexComp ? "\\f" : "\f");
break;
}
case 'v':
{
res.Append(processRegexComp ? "\\v" : "\v");
break;
}
{
res.Append(processRegexComp ? "\\v" : "\v");
break;
}
case 'b':
{
res.Append(processRegexComp ? "\\b" : "\b");
break;
}
{
res.Append(processRegexComp ? "\\b" : "\b");
break;
}
case 'n':
{
res.Append(processRegexComp ? "\\n" : "\n");
break;
}
{
res.Append(processRegexComp ? "\\n" : "\n");
break;
}
case 'r':
{
res.Append(processRegexComp ? "\\r" : "\r");
break;
}
{
res.Append(processRegexComp ? "\\r" : "\r");
break;
}
case '\n':
{
break;
}
{
break;
}
case '\r':
{
if (code.Length > i + 1 && code[i + 1] == '\n')
i++;
break;
}
{
if (code.Length > i + 1 && code[i + 1] == '\n')
i++;
break;
}
case 'c':
case 'C':
{
if (!processRegexComp)
goto default;
{
if (!processRegexComp)
goto default;

if (i + 1 < code.Length)
if (i + 1 < code.Length)
{
char ch = code[i + 1];
// convert a -> A
if (ch >= 'a' && ch <= 'z')
ch = (char)(ch - ('a' - 'A'));
if ((char)(ch - '@') < ' ')
{
char ch = code[i + 1];
// convert a -> A
if (ch >= 'a' && ch <= 'z')
ch = (char)(ch - ('a' - 'A'));
if ((char)(ch - '@') < ' ')
{
res.Append("\\c");
res.Append(ch);
++i;
break;
}
res.Append("\\c");
res.Append(ch);
++i;
break;
}

// invalid control character
goto case 'p';
}

// invalid control character
goto case 'p';
}
// not supported in standard
case 'P':
case 'p':
case 'k':
case 'K':
{
if (!processRegexComp)
goto default;

// regex that does not match anything
res.Append(@"\b\B");
break;
}
default:
{
if (!processRegexComp && code[i] >= '0' && code[i] <= '7')
{
if (!processRegexComp)
goto default;
if (strict && (code[i] != '0' || (code.Length > i + 1 && code[i + 1] >= '0' && code[i + 1] <= '7')))
ExceptionHelper.Throw(new SyntaxError("Octal literals are not allowed in strict mode."));

// regex that does not match anything
res.Append(@"\b\B");
break;
var ccode = code[i] - '0';
if (i + 1 < code.Length && code[i + 1] >= '0' && code[i + 1] <= '7')
ccode = ccode * 8 + (code[++i] - '0');
if (i + 1 < code.Length && code[i + 1] >= '0' && code[i + 1] <= '7')
ccode = ccode * 8 + (code[++i] - '0');
res.Append((char)ccode);
}
default:
else if (processUnknown)
{
if (code[i] >= '0' && code[i] <= '7' && !processRegexComp)
{
if (strict)
ExceptionHelper.Throw((new SyntaxError("Octal literals are not allowed in strict mode.")));

var ccode = code[i] - '0';
if (i + 1 < code.Length && code[i + 1] >= '0' && code[i + 1] <= '7')
ccode = ccode * 8 + (code[++i] - '0');
if (i + 1 < code.Length && code[i + 1] >= '0' && code[i + 1] <= '7')
ccode = ccode * 8 + (code[++i] - '0');
res.Append((char)ccode);
}
else if (processUnknown)
{
res.Append(code[i]);
}
else
{
res.Append('\\');
res.Append(code[i]);
}
break;
res.Append(code[i]);
}
else
{
res.Append('\\');
res.Append(code[i]);
}
break;
}
}
}
else if (res != null)
Expand Down
Loading

0 comments on commit aaee503

Please sign in to comment.