summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-09-13 18:20:36 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-09-13 18:20:36 -0400
commita40ef854f3769a0e5d3c2629de538e272a6fcecf (patch)
treee225d8bae282816d114db0f060d115f0c61ed640
parent4fccaa35709440f98e275f0da3d2b65204b7d6e2 (diff)
downloadSMAPI-a40ef854f3769a0e5d3c2629de538e272a6fcecf.tar.gz
SMAPI-a40ef854f3769a0e5d3c2629de538e272a6fcecf.tar.bz2
SMAPI-a40ef854f3769a0e5d3c2629de538e272a6fcecf.zip
fix JSON validator line numbers sometimes incorrect
-rw-r--r--docs/release-notes.md3
-rw-r--r--src/SMAPI.Web/Controllers/JsonValidatorController.cs26
2 files changed, 19 insertions, 10 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 0678f6e1..ddd0526b 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -8,6 +8,9 @@
* For mod authors:
* 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
Released 03 September 2021 for Stardew Valley 1.5.4 or later.
diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs
index c77a3036..e06c1236 100644
--- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs
+++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs
@@ -90,21 +90,27 @@ namespace StardewModdingAPI.Web.Controllers
// parse JSON
JToken parsed;
- try
{
- parsed = JToken.Parse(file.Content, new JsonLoadSettings
+ // load raw JSON
+ var settings = new JsonLoadSettings
{
DuplicatePropertyNameHandling = DuplicatePropertyNameHandling.Error,
CommentHandling = CommentHandling.Load
- });
- }
- catch (JsonReaderException ex)
- {
- return this.View("Index", result.AddErrors(new JsonValidatorErrorModel(ex.LineNumber, ex.Path, ex.Message, ErrorType.None)));
- }
+ };
+ try
+ {
+ parsed = JToken.Parse(file.Content, settings);
+ }
+ catch (JsonReaderException ex)
+ {
+ return this.View("Index", result.AddErrors(new JsonValidatorErrorModel(ex.LineNumber, ex.Path, ex.Message, ErrorType.None)));
+ }
- // format JSON
- result.SetContent(parsed.ToString(Formatting.Indented), expiry: file.Expiry, uploadWarning: file.Warning);
+ // format JSON
+ 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
if (schemaName == "none")