From ed47d5fc7b4bbe9324655218a5d0c13aa89bf8c1 Mon Sep 17 00:00:00 2001 From: grandsilence Date: Mon, 22 Oct 2018 19:42:51 +0300 Subject: [PATCH] Fix JSON escape --- Leaf.Core/Extensions/String/StringExtensions.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Leaf.Core/Extensions/String/StringExtensions.cs b/Leaf.Core/Extensions/String/StringExtensions.cs index e1a03d2..4d204cd 100644 --- a/Leaf.Core/Extensions/String/StringExtensions.cs +++ b/Leaf.Core/Extensions/String/StringExtensions.cs @@ -107,13 +107,18 @@ public static byte[] HexStringToBytes(this string hexString) /// Экранирует " символы и символы юникода в JSON. /// /// JSON данные + /// Следует ли экранировать символы юникода /// Вернет экранированные данные. - public static string EscapeJsonData(this string jsonData) + public static string EscapeJsonData(this string jsonData, bool escapeUnicode) { - return jsonData - .Replace("\"", "\\\"") + string result = jsonData .Replace("\\", "\\\\") - .EncodeJsonUnicode(); + .Replace("\"", "\\\""); + + if (escapeUnicode) + result = result.EncodeJsonUnicode(); + + return result; } ///