Add ReplaceLineBreaks extension and Fix bug

https://github.com/2dust/v2rayN/issues/9497
This commit is contained in:
2dust
2026-06-07 14:49:39 +08:00
parent f0ee792778
commit 5fed566a32
2 changed files with 19 additions and 5 deletions
+16
View File
@@ -118,4 +118,20 @@ public static class Extension
destination.Add(item); destination.Add(item);
} }
} }
/// <summary>
/// Replace all cross-platform newline characters with the specified string
/// </summary>
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);
}
} }
+3 -5
View File
@@ -51,7 +51,7 @@ public class Utils
try try
{ {
str = str.Replace(Environment.NewLine, string.Empty); str = str.ReplaceLineBreaks(string.Empty);
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries)); return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
} }
catch (Exception ex) catch (Exception ex)
@@ -114,9 +114,7 @@ public class Utils
} }
plainText = plainText.Trim() plainText = plainText.Trim()
.Replace(Environment.NewLine, "") .ReplaceLineBreaks("")
.Replace("\n", "")
.Replace("\r", "")
.Replace('_', '/') .Replace('_', '/')
.Replace('-', '+') .Replace('-', '+')
.Replace(" ", ""); .Replace(" ", "");
@@ -321,7 +319,7 @@ public class Utils
return text; return text;
} }
return text.Replace(",", ",").Replace(Environment.NewLine, ","); return text.Replace(" ", "").ReplaceLineBreaks(",");
} }
public static List<string> GetEnumNames<TEnum>() where TEnum : Enum public static List<string> GetEnumNames<TEnum>() where TEnum : Enum