Fix handling of empty constructor names (#2922)
Co-authored-by: James Newton-King <james@newtonking.com>
This commit is contained in:
co-authored by
James Newton-King
parent
01e1759cac
commit
55a7204f9b
@@ -118,6 +118,17 @@ namespace Newtonsoft.Json.Tests
|
||||
}, "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()
|
||||
{
|
||||
@@ -1830,4 +1841,4 @@ namespace Newtonsoft.Json.Tests
|
||||
public DateTime Expiration { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1937,6 +1937,11 @@ namespace Newtonsoft.Json
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user