Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support comments in recipes #15386

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.IO.Compression;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -129,7 +130,7 @@ public async Task<IActionResult> Json(ImportJsonViewModel model)
return Forbid();
}

if (!model.Json.IsJson())
if (!model.Json.IsJson(null, JOptions.Document))
{
ModelState.AddModelError(nameof(model.Json), S["The recipe is written in an incorrect json format."]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static JOptions()

Document = new JsonDocumentOptions
{
CommentHandling = Default.ReadCommentHandling,
AllowTrailingCommas = Default.AllowTrailingCommas,
CommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@ private JsonConfigurationParser() { }

private async Task<IDictionary<string, string?>> ParseStreamAsync(Stream input)
{
var jsonDocumentOptions = new JsonDocumentOptions
{
CommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};

try
{
using (var doc = await JsonDocument.ParseAsync(input, jsonDocumentOptions))
using (var doc = await JsonDocument.ParseAsync(input, JOptions.Document))
{
if (doc.RootElement.ValueKind != JsonValueKind.Object)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using Cysharp.Text;
Expand Down Expand Up @@ -501,11 +502,11 @@ public static string ToPascalCase(this string attribute, char upperAfterDelimite
/// <summary>
/// Tests if a string is valid json.
/// </summary>
public static bool IsJson(this string json)
public static bool IsJson(this string json, JsonNodeOptions? jsonNodeOptions = null, JsonDocumentOptions jsonDocumentOptions = default)
{
try
{
JsonNode.Parse(json);
JsonNode.Parse(json, jsonNodeOptions, jsonDocumentOptions);
return true;
}
catch
Expand Down
Loading