示例#1
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);
        }