From f49a9629d9dcf212928b5256a09ef49a865b757e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Fri, 21 Nov 2025 14:53:44 -0300 Subject: [PATCH] Fix missing control characters in Json Parse Key --- Jint.Tests/Runtime/JsonTests.cs | 16 +++++++++++----- Jint/Native/Json/JsonParser.cs | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Jint.Tests/Runtime/JsonTests.cs b/Jint.Tests/Runtime/JsonTests.cs index e8b896cf92..38b003acf9 100644 --- a/Jint.Tests/Runtime/JsonTests.cs +++ b/Jint.Tests/Runtime/JsonTests.cs @@ -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] @@ -314,4 +320,4 @@ private static string GenerateDeepNestedObject(int depth, string mostInnerValue) string objectClose = new string('}', depth); return $"{objectOpen}{mostInnerValue}{objectClose}"; } -} \ No newline at end of file +} diff --git a/Jint/Native/Json/JsonParser.cs b/Jint/Native/Json/JsonParser.cs index f0c94b82b9..a7f6a72069 100644 --- a/Jint/Native/Json/JsonParser.cs +++ b/Jint/Native/Json/JsonParser.cs @@ -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; }