Skip to content
Merged
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
Prev Previous commit
Next Next commit
Fix JsonWriterOptions copy to avoid mutating context options
Co-authored-by: sebastienros <[email protected]>
  • Loading branch information
Copilot and sebastienros committed Nov 1, 2025
commit c01e1616d7f3664aa64d57093315f57a1fbd0733
15 changes: 10 additions & 5 deletions Fluid/Filters/MiscFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,16 @@ public static async ValueTask<FluidValue> Json(FluidValue input, FilterArguments
using var ms = new MemoryStream();

// Start with context.JsonWriterOptions, but allow argument to override Indented
var writerOptions = context.JsonWriterOptions;
if (!arguments.At(0).IsNil())
{
writerOptions.Indented = arguments.At(0).ToBooleanValue();
}
// Create a new instance to avoid modifying the context's options
var writerOptions = new JsonWriterOptions
{
Encoder = context.JsonWriterOptions.Encoder,
Indented = arguments.At(0).IsNil()
? context.JsonWriterOptions.Indented
: arguments.At(0).ToBooleanValue(),
MaxDepth = context.JsonWriterOptions.MaxDepth,
SkipValidation = context.JsonWriterOptions.SkipValidation
};

await using (var writer = new Utf8JsonWriter(ms, writerOptions))
{
Expand Down