Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion Src/Newtonsoft.Json.Tests/JsonConvertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ public void PopulateObjectWithNoContent()
}, "No JSON content found. Path '', line 0, position 0.");
}

[Test]
public void NoConstructorName() {
ExceptionAssert.Throws<JsonException>(
() => JsonConvert.DeserializeObject("[new \0("),
"Empty constructor name. Path '', line 1, position 6.");

ExceptionAssert.Throws<JsonException>(
() => JsonConvert.DeserializeObject("{'x':new \0("),
"Empty constructor name. Path 'x', line 1, position 10.");
}

[Test]
public void PopulateObjectWithOnlyComment()
{
Expand Down Expand Up @@ -1830,4 +1841,4 @@ private int _expiration
public DateTime Expiration { get; set; }
}
}
}
}
4 changes: 4 additions & 0 deletions Src/Newtonsoft.Json/JsonTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,10 @@ private void ParseConstructor()
throw JsonReaderException.Create(this, "Unexpected character while parsing constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
}
}

if (initialPosition == endPosition) {
throw JsonReaderException.Create(this, "Empty constructor name.");
}

_stringReference = new StringReference(_chars, initialPosition, endPosition - initialPosition);
string constructorName = _stringReference.ToString();
Expand Down