Пример #1
0
        public static string HtmlFormUrlEncode(string input, Encoding inputEncoding)
        {
            // Assuming the default to be UTF-8
            if (inputEncoding == null)
            {
                inputEncoding = Encoding.UTF8;
            }

            return(HtmlParameterEncoder.FormStringParameterEncode(input, inputEncoding));
        }
Пример #2
0
        protected internal override string UrlPathEncode(string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(value);
            }

            // DevDiv #211105: We should make the UrlPathEncode method encode only the path portion of URLs.

            string schemeAndAuthority;
            string path;
            string queryAndFragment;
            bool   isValidUrl = UriUtil.TrySplitUriForPathEncode(value, out schemeAndAuthority, out path, out queryAndFragment, checkScheme: false);

            if (!isValidUrl)
            {
                // treat as a relative URL, so we might still need to chop off the query / fragment components
                schemeAndAuthority = null;
                UriUtil.ExtractQueryAndFragment(value, out path, out queryAndFragment);
            }

            return(schemeAndAuthority + HtmlParameterEncoder.UrlPathEncode(path, Encoding.UTF8) + queryAndFragment);
        }