diff --git a/websocket-sharp/Net/HttpUtility.cs b/websocket-sharp/Net/HttpUtility.cs index 08abb41e..c436d9ff 100644 --- a/websocket-sharp/Net/HttpUtility.cs +++ b/websocket-sharp/Net/HttpUtility.cs @@ -1027,45 +1027,7 @@ namespace WebSocketSharp.Net if (s == null) throw new ArgumentNullException ("s"); - if (s.Length == 0) - return s; - - var buff = new StringBuilder (); - - foreach (var c in s) { - if (c == '&') { - buff.Append ("&"); - continue; - } - - if (c == '"') { - buff.Append ("""); - continue; - } - - if (c == '<') { - buff.Append ("<"); - continue; - } - - if (c == '>') { - buff.Append (">"); - continue; - } - - if (c > 159) { - // MS .NET starts encoding with &# from 160 and stops at 255. - // We do not do that. One reason is the 65308/65310 unicode - // characters that look like '<' and '>'. - - buff.AppendFormat ("&#{0};", (int) c); - continue; - } - - buff.Append (c); - } - - return buff.ToString (); + return s.Length > 0 ? htmlEncode (s) : s; } public static void HtmlEncode (string s, TextWriter output)