Skip to content

Commit

Permalink
Fix JSON escape
Browse files Browse the repository at this point in the history
  • Loading branch information
grandsilence committed Oct 22, 2018
1 parent 301682c commit ed47d5f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Leaf.Core/Extensions/String/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ public static byte[] HexStringToBytes(this string hexString)
/// Экранирует " символы и символы юникода в JSON.
/// </summary>
/// <param name="jsonData">JSON данные</param>
/// <param name="escapeUnicode">Следует ли экранировать символы юникода</param>
/// <returns>Вернет экранированные данные.</returns>
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;
}

/// <summary>
Expand Down

0 comments on commit ed47d5f

Please sign in to comment.