fix JSON validator line numbers sometimes incorrect
This commit is contained in:
parent
4fccaa3570
commit
a40ef854f3
|
@ -8,6 +8,9 @@
|
||||||
* For mod authors:
|
* For mod authors:
|
||||||
* Improved SMAPI's crossplatform read/writing of `Color`, `Point`, `Rectangle`, and `Vector2` in JSON to support nullable fields too.
|
* Improved SMAPI's crossplatform read/writing of `Color`, `Point`, `Rectangle`, and `Vector2` in JSON to support nullable fields too.
|
||||||
|
|
||||||
|
* For the web UI:
|
||||||
|
* Fixed JSON validator line numbers sometimes incorrect.
|
||||||
|
|
||||||
## 3.12.6
|
## 3.12.6
|
||||||
Released 03 September 2021 for Stardew Valley 1.5.4 or later.
|
Released 03 September 2021 for Stardew Valley 1.5.4 or later.
|
||||||
|
|
||||||
|
|
|
@ -90,21 +90,27 @@ namespace StardewModdingAPI.Web.Controllers
|
||||||
|
|
||||||
// parse JSON
|
// parse JSON
|
||||||
JToken parsed;
|
JToken parsed;
|
||||||
try
|
|
||||||
{
|
{
|
||||||
parsed = JToken.Parse(file.Content, new JsonLoadSettings
|
// load raw JSON
|
||||||
|
var settings = new JsonLoadSettings
|
||||||
{
|
{
|
||||||
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error,
|
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error,
|
||||||
CommentHandling = CommentHandling.Load
|
CommentHandling = CommentHandling.Load
|
||||||
});
|
};
|
||||||
}
|
try
|
||||||
catch (JsonReaderException ex)
|
{
|
||||||
{
|
parsed = JToken.Parse(file.Content, settings);
|
||||||
return this.View("Index", result.AddErrors(new JsonValidatorErrorModel(ex.LineNumber, ex.Path, ex.Message, ErrorType.None)));
|
}
|
||||||
}
|
catch (JsonReaderException ex)
|
||||||
|
{
|
||||||
|
return this.View("Index", result.AddErrors(new JsonValidatorErrorModel(ex.LineNumber, ex.Path, ex.Message, ErrorType.None)));
|
||||||
|
}
|
||||||
|
|
||||||
// format JSON
|
// format JSON
|
||||||
result.SetContent(parsed.ToString(Formatting.Indented), expiry: file.Expiry, uploadWarning: file.Warning);
|
string formatted = parsed.ToString(Formatting.Indented);
|
||||||
|
result.SetContent(formatted, expiry: file.Expiry, uploadWarning: file.Warning);
|
||||||
|
parsed = JToken.Parse(formatted); // update line number references
|
||||||
|
}
|
||||||
|
|
||||||
// skip if no schema selected
|
// skip if no schema selected
|
||||||
if (schemaName == "none")
|
if (schemaName == "none")
|
||||||
|
|
Loading…
Reference in New Issue