From 5fed566a324569da59252d8ee8179e22ff21a035 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 7 Jun 2026 14:49:39 +0800 Subject: [PATCH] Add ReplaceLineBreaks extension and Fix bug https://github.com/2dust/v2rayN/issues/9497 --- v2rayN/ServiceLib/Common/Extension.cs | 16 ++++++++++++++++ v2rayN/ServiceLib/Common/Utils.cs | 8 +++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/v2rayN/ServiceLib/Common/Extension.cs b/v2rayN/ServiceLib/Common/Extension.cs index a5cfdc38..e3ed703d 100644 --- a/v2rayN/ServiceLib/Common/Extension.cs +++ b/v2rayN/ServiceLib/Common/Extension.cs @@ -118,4 +118,20 @@ public static class Extension destination.Add(item); } } + + /// + /// Replace all cross-platform newline characters with the specified string + /// + public static string ReplaceLineBreaks(this string input, string replacement) + { + if (string.IsNullOrEmpty(input)) + { + return input; + } + + // You must replace \r\n first, and then replace the single characters \r and \n. + return input.Replace("\r\n", replacement) + .Replace("\r", replacement) + .Replace("\n", replacement); + } } diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 9c2bd4af..1f4e0be9 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -51,7 +51,7 @@ public class Utils try { - str = str.Replace(Environment.NewLine, string.Empty); + str = str.ReplaceLineBreaks(string.Empty); return new List(str.Split(',', StringSplitOptions.RemoveEmptyEntries)); } catch (Exception ex) @@ -114,9 +114,7 @@ public class Utils } plainText = plainText.Trim() - .Replace(Environment.NewLine, "") - .Replace("\n", "") - .Replace("\r", "") + .ReplaceLineBreaks("") .Replace('_', '/') .Replace('-', '+') .Replace(" ", ""); @@ -321,7 +319,7 @@ public class Utils return text; } - return text.Replace(",", ",").Replace(Environment.NewLine, ","); + return text.Replace(" ", "").ReplaceLineBreaks(","); } public static List GetEnumNames() where TEnum : Enum