Exemple #1
0
        protected internal virtual string UrlPathEncode(string value)
        {
            // DevDiv 995259: HttpUtility.UrlPathEncode should not encode IDN part of the url
            if (BinaryCompatibility.Current.TargetsAtLeastFramework46)
            {
                if (String.IsNullOrEmpty(value))
                {
                    return(value);
                }

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

                if (!isValidUrl)
                {
                    // If the value is not a valid url, we treat it as a relative url.
                    // We don't need to extract query string from the url since UrlPathEncode()
                    // does not encode query string.
                    schemeAndAuthority = null;
                    path             = value;
                    queryAndFragment = null;
                }

                return(schemeAndAuthority + UrlPathEncodeImpl(path) + queryAndFragment);
            }
            else
            {
                return(UrlPathEncodeImpl(value));
            }
        }
Exemple #2
0
        internal static string UrlPathEncode(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }

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

            if (!isValidUrl)
            {
                // If the value is not a valid url, we treat it as a relative url.
                // We don't need to extract query string from the url since UrlPathEncode()
                // does not encode query string.
                schemeAndAuthority = null;
                path             = value;
                queryAndFragment = null;
            }

            return(schemeAndAuthority + UrlPathEncodeImpl(path) + queryAndFragment);
        }