From 195cc62ff5d747e61991de6c8918fc8113a7be8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nenberger=20Tim?= Date: Thu, 30 Apr 2026 09:40:41 +0200 Subject: [PATCH] fix: prevent unicode escaping of '+' in variable get output JsonNode.ToJsonString() uses JavaScriptEncoder.Default which unnecessarily escapes '+' (U+002B) as \u002b in the output. - VariableGetPipeline: use result.ToString() for console display to get the raw string value without JSON encoding artifacts - JsonNodeOutputFormatter: pass JavaScriptEncoder.UnsafeRelaxedJsonEscaping to ToJsonString() so --format json output preserves '+' literally --- .../src/Confix.Library/Output/JsonNodeOutputFormatter.cs | 9 ++++++++- .../Pipelines/Variable/VariableGetPipeline.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Confix.Tool/src/Confix.Library/Output/JsonNodeOutputFormatter.cs b/src/Confix.Tool/src/Confix.Library/Output/JsonNodeOutputFormatter.cs index 941e5b8..b7bd3bb 100644 --- a/src/Confix.Tool/src/Confix.Library/Output/JsonNodeOutputFormatter.cs +++ b/src/Confix.Tool/src/Confix.Library/Output/JsonNodeOutputFormatter.cs @@ -1,3 +1,5 @@ +using System.Text.Encodings.Web; +using System.Text.Json; using System.Text.Json.Nodes; using Confix.Tool.Commands.Logging; using Confix.Tool.Reporting; @@ -6,6 +8,11 @@ namespace Confix.Tool.Commands.Configuration; public sealed class JsonNodeOutputFormatter : IOutputFormatter { + private static readonly JsonSerializerOptions _options = new() + { + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }; + /// public bool CanHandle(OutputFormat format, JsonNode value) => format == OutputFormat.Json; @@ -13,6 +20,6 @@ public bool CanHandle(OutputFormat format, JsonNode value) /// public Task FormatAsync(OutputFormat format, JsonNode value) { - return Task.FromResult(value.ToJsonString()); + return Task.FromResult(value.ToJsonString(_options)); } } diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs index e2ef8dd..518fce3 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs @@ -38,7 +38,7 @@ private static async Task InvokeAsync(IMiddlewareContext context) var result = await resolver .ResolveOrThrowAsync(variablePath, variableContext); - context.Logger.PrintVariableResolved(variablePath, result.ToJsonString()); + context.Logger.PrintVariableResolved(variablePath, result.ToString()); context.SetOutput(result); }