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
16 changes: 11 additions & 5 deletions Jint.Tests/Runtime/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ namespace Jint.Tests.Runtime;

public class JsonTests
{
[Fact]
public void CanParseTabsInProperties()
[Theory]
[InlineData(@"JSON.parse(""{\""abc\\tdef\"": \""42\""}"");", "abc\tdef")]
[InlineData(@"JSON.parse(""{\""abc\\ndef\"": \""42\""}"");", "abc\ndef")]
[InlineData(@"JSON.parse(""{\""abc\\fdef\"": \""42\""}"");", "abc\fdef")]
[InlineData(@"JSON.parse(""{\""abc\\bdef\"": \""42\""}"");", "abc\bdef")]
[InlineData(@"JSON.parse(""{\""abc\\rdef\"": \""42\""}"");", "abc\rdef")]
[InlineData(@"JSON.parse(""{\""abc\\r\\ndef\"": \""42\""}"");", "abc\r\ndef")]
[InlineData(@"JSON.parse(""{\""abc\\\""def\"": \""42\""}"");", "abc\"def")]
public void CanParseEscapeSequencesInProperties(string script, string expectedPropertyName)
{
var engine = new Engine();
const string script = @"JSON.parse(""{\""abc\\tdef\"": \""42\""}"");";
var obj = engine.Evaluate(script).AsObject();
Assert.True(obj.HasOwnProperty("abc\tdef"));
Assert.True(obj.HasOwnProperty(expectedPropertyName));
}

[Theory]
Expand Down Expand Up @@ -314,4 +320,4 @@ private static string GenerateDeepNestedObject(int depth, string mostInnerValue)
string objectClose = new string('}', depth);
return $"{objectOpen}{mostInnerValue}{objectClose}";
}
}
}
2 changes: 1 addition & 1 deletion Jint/Native/Json/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ private static bool PropertyNameContainsInvalidCharacters(string propertyName)
const char max = (char) 31;
foreach (var c in propertyName)
{
if (c != '\t' && c <= max)
if (c != '\t' && c != '\n' && c != '\r' && c != '\b' && c != '\f' && c <= max)
{
return true;
}
Expand Down