Esempio n. 1
0
 internal static void HeaderNameValueEncode(string headerName, string headerValue, out string encodedHeaderName, out string encodedHeaderValue)
 {
     encodedHeaderName  = ((!string.IsNullOrEmpty(headerName)) ? HttpEncoder.EncodeHeaderString(headerName) : headerName);
     encodedHeaderValue = ((!string.IsNullOrEmpty(headerValue)) ? HttpEncoder.EncodeHeaderString(headerValue) : headerValue);
 }
Esempio n. 2
0
 static HttpEncoder()
 {
     defaultEncoder = new HttpEncoder();
     currentEncoder = defaultEncoder;
 }
Esempio n. 3
0
        internal static string HtmlDecode(string s)
        {
            if (s == null)
            {
                return(null);
            }
            if (s.Length == 0)
            {
                return(string.Empty);
            }
            if (s.IndexOf('&') == -1)
            {
                return(s);
            }
            StringBuilder stringBuilder  = new StringBuilder();
            StringBuilder stringBuilder2 = new StringBuilder();
            int           length         = s.Length;
            int           num            = 0;
            int           num2           = 0;
            bool          flag           = false;
            bool          flag2          = false;

            for (int i = 0; i < length; i++)
            {
                char c = s[i];
                if (num == 0)
                {
                    if (c == '&')
                    {
                        stringBuilder.Append(c);
                        num = 1;
                    }
                    else
                    {
                        stringBuilder2.Append(c);
                    }
                }
                else if (c == '&')
                {
                    num = 1;
                    if (flag2)
                    {
                        stringBuilder.Append(num2.ToString(Helpers.InvariantCulture));
                        flag2 = false;
                    }
                    stringBuilder2.Append(stringBuilder);
                    stringBuilder.Length = 0;
                    stringBuilder.Append('&');
                }
                else
                {
                    switch (num)
                    {
                    case 1:
                        if (c == ';')
                        {
                            num = 0;
                            stringBuilder2.Append(stringBuilder);
                            stringBuilder2.Append(c);
                            stringBuilder.Length = 0;
                        }
                        else
                        {
                            num2 = 0;
                            flag = false;
                            num  = ((c == '#') ? 3 : 2);
                            stringBuilder.Append(c);
                        }
                        break;

                    case 2:
                        stringBuilder.Append(c);
                        if (c == ';')
                        {
                            string text = stringBuilder.ToString();
                            if (text.Length > 1 && HttpEncoder.Entities.ContainsKey(text.Substring(1, text.Length - 2)))
                            {
                                text = HttpEncoder.Entities[text.Substring(1, text.Length - 2)].ToString();
                            }
                            stringBuilder2.Append(text);
                            num = 0;
                            stringBuilder.Length = 0;
                        }
                        break;

                    case 3:
                        if (c == ';')
                        {
                            if (num2 > 65535)
                            {
                                stringBuilder2.Append("&#");
                                stringBuilder2.Append(num2.ToString(Helpers.InvariantCulture));
                                stringBuilder2.Append(";");
                            }
                            else
                            {
                                stringBuilder2.Append((char)num2);
                            }
                            num = 0;
                            stringBuilder.Length = 0;
                            flag2 = false;
                        }
                        else if (flag && HttpEncoder.IsHexDigit(c))
                        {
                            num2  = num2 * 16 + HttpEncoder.FromHex(c);
                            flag2 = true;
                        }
                        else if (char.IsDigit(c))
                        {
                            num2  = num2 * 10 + (int)(c - '0');
                            flag2 = true;
                        }
                        else if (num2 == 0 && (c == 'x' || c == 'X'))
                        {
                            flag = true;
                        }
                        else
                        {
                            num = 2;
                            if (flag2)
                            {
                                stringBuilder.Append(num2.ToString(Helpers.InvariantCulture));
                                flag2 = false;
                            }
                            stringBuilder.Append(c);
                        }
                        break;
                    }
                }
            }
            if (stringBuilder.Length > 0)
            {
                stringBuilder2.Append(stringBuilder);
            }
            else if (flag2)
            {
                stringBuilder2.Append(num2.ToString(Helpers.InvariantCulture));
            }
            return(stringBuilder2.ToString());
        }
Esempio n. 4
0
 static HttpEncoder()
 {
     defaultEncoder = new HttpEncoder();
     currentEncoder = defaultEncoder;
 }
Esempio n. 5
0
 public static string HtmlAttributeEncode(string s)
 {
     return(HttpEncoder.HtmlAttributeEncode(s));
 }
Esempio n. 6
0
 public static string UrlPathEncode(string s)
 {
     return(HttpEncoder.UrlPathEncode(s));
 }
Esempio n. 7
0
 /// <summary>
 /// Decodes an HTML-encoded string and returns the decoded string.
 /// </summary>
 /// <param name="s">The HTML string to decode. </param>
 /// <returns>The decoded text.</returns>
 public static string HtmlDecode(string s)
 {
     return(HttpEncoder.HtmlDecode(s));
 }