From 23f8ad2fbcfb53a7cc1d62fe51a132c47cb33a58 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Wed, 26 Nov 2025 12:51:22 +0800 Subject: [PATCH] Format imported xhttp extra --- v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs | 39 ++++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs index ffcd15c5..3665afdf 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs @@ -118,22 +118,15 @@ public class BaseFmt } if (item.Extra.IsNotEmpty()) { - var extra = item.Extra; - try - { - var node = JsonNode.Parse(item.Extra); - if (node != null) + var node = JsonUtils.ParseJson(item.Extra); + var extra = node != null + ? JsonUtils.Serialize(node, new JsonSerializerOptions { - extra = node.ToJsonString(new JsonSerializerOptions - { - WriteIndented = false, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping - }); - } - } - catch - { - } + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.Never, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }) + : item.Extra; dicQuery.Add("extra", Utils.UrlEncode(extra)); } break; @@ -253,7 +246,21 @@ public class BaseFmt item.RequestHost = GetQueryDecoded(query, "host"); item.Path = GetQueryDecoded(query, "path", "/"); item.HeaderType = GetQueryDecoded(query, "mode"); - item.Extra = GetQueryDecoded(query, "extra"); + var extraDecoded = GetQueryDecoded(query, "extra"); + if (extraDecoded.IsNotEmpty()) + { + var node = JsonUtils.ParseJson(extraDecoded); + if (node != null) + { + extraDecoded = JsonUtils.Serialize(node, new JsonSerializerOptions + { + WriteIndented = true, + DefaultIgnoreCondition = JsonIgnoreCondition.Never, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }); + } + } + item.Extra = extraDecoded; break; case nameof(ETransport.http):