internal static string AddParameter(string baseUrl, string parameter, string value) { // this will get our url's properly formatted if (parameter == Constants.UrlParameter.Url) { try { value = new Uri (value).ToString(); } catch (UriFormatException e) { UriFormatException ufe = new UriFormatException ("Delicious.Net was unable to parse the url \"" + value + "\".\n\n" + e); throw (ufe); } } //value = HttpUtility.UrlEncode (value); // insert the '?' if needed int qLocation = baseUrl.LastIndexOf ('?'); if (qLocation < 0) { baseUrl += "?"; qLocation = baseUrl.Length - 1; } if (baseUrl.Length > qLocation + 1) baseUrl += "&"; baseUrl += parameter + "=" + value; return baseUrl; }
protected override void InitializeAndValidate (Uri uri, out UriFormatException parsingError) { if (uri.Scheme == "httpx") parsingError = null; else base.InitializeAndValidate (uri, out parsingError); }
public void LinkDemand_GetObjectData_Deny_DenySerializationFormatter () { StreamingContext sc = new StreamingContext (StreamingContextStates.All); UriFormatException ufe = new UriFormatException (); MethodInfo mi = ufe.GetType ().GetMethod ("GetObjectData"); Assert.IsNotNull (mi, "GetObjectData"); Assert.IsNotNull (mi.Invoke (ufe, new object[2] { null, sc }), "invoke"); }
/// <summary>Initialize the state of the parser and validate the URI.</summary> /// <param name="uri">The T:System.Uri to validate.</param> /// <param name="parsingError">Validation errors, if any.</param> protected internal virtual void InitializeAndValidate(System.Uri uri, out System.UriFormatException parsingError) { if (uri.Scheme != this.scheme_name && this.scheme_name != "*") { parsingError = new System.UriFormatException("The argument Uri's scheme does not match"); } else { parsingError = null; } }
// // Resolves a relative Uri object into new AbsoluteUri. // // baseUri - The baseUri used to resolve this Uri. // relativeuri - A relative Uri string passed by the application. // // This method returns: // The result Uri value used to represent a new Uri // protected virtual string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { if (baseUri.UserDrivenParsing) throw new InvalidOperationException(SR.Format(SR.net_uri_UserDrivenParsing, this.GetType().ToString())); if (!baseUri.IsAbsoluteUri) throw new InvalidOperationException(SR.net_uri_NotAbsolute); string newUriString = null; bool userEscaped = false; Uri result = Uri.ResolveHelper(baseUri, relativeUri, ref newUriString, ref userEscaped, out parsingError); if (parsingError != null) return null; if (result != null) return result.OriginalString; return newUriString; }
protected virtual string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { if (baseUri.UserDrivenParsing) { throw new InvalidOperationException(SR.GetString("net_uri_UserDrivenParsing", new object[] { base.GetType().FullName })); } if (!baseUri.IsAbsoluteUri) { throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute")); } string newUriString = null; bool userEscaped = false; Uri uri = Uri.ResolveHelper(baseUri, relativeUri, ref newUriString, ref userEscaped, out parsingError); if (parsingError != null) { return(null); } if (uri != null) { return(uri.OriginalString); } return(newUriString); }
// // a Uri.TryCreate() method goes through here. // internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e) { // if (!Enum.IsDefined(typeof(UriKind), uriKind)) -- We currently believe that Enum.IsDefined() is too slow // to be used here. if ((int)uriKind < (int)UriKind.RelativeOrAbsolute || (int)uriKind > (int)UriKind.Relative) { throw new ArgumentException(SR.Format(SR.net_uri_InvalidUriKind, uriKind)); } UriParser syntax = null; Flags flags = Flags.Zero; ParsingError err = ParseScheme(uriString, ref flags, ref syntax); if (dontEscape) { flags |= Flags.UserEscaped; } // We won't use User factory for these errors if (err != ParsingError.None) { // If it looks as a relative Uri, custom factory is ignored if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { return(new Uri((flags & Flags.UserEscaped), null, uriString)); } return(null); } // Cannot be relative Uri if came here Uri result = new Uri(flags, syntax, uriString); // Validate instance using ether built in or a user Parser try { result.InitializeUri(err, uriKind, out e); if (e == null) { return(result); } return(null); } catch (UriFormatException ee) { Debug.Assert(!syntax.IsSimple, "A UriPraser threw on InitializeAndValidate."); e = ee; // A precaution since custom Parser should never throw in this case. return(null); } }
protected internal virtual string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { // used by Uri.ctor and Uri.TryCreate throw new NotImplementedException(); }
internal void InternalValidate(Uri thisUri, out UriFormatException parsingError) { InitializeAndValidate(thisUri, out parsingError); }
protected override void InitializeAndValidate (Uri uri, out UriFormatException parsingError) { base.InitializeAndValidate (uri, out parsingError); }
private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatException e) { if (err == ParsingError.None) { if (this.IsImplicitFile) { if ((this.NotAny(Flags.DosPath) && (uriKind != UriKind.Absolute)) && ((uriKind == UriKind.Relative) || ((this.m_String.Length >= 2) && ((this.m_String[0] != '\\') || (this.m_String[1] != '\\'))))) { this.m_Syntax = null; this.m_Flags &= Flags.HostNotParsed | Flags.UserEscaped; e = null; return; } if ((uriKind == UriKind.Relative) && this.InFact(Flags.DosPath)) { this.m_Syntax = null; this.m_Flags &= Flags.HostNotParsed | Flags.UserEscaped; e = null; return; } } } else if (err > ParsingError.EmptyUriString) { this.m_String = null; e = GetException(err); return; } bool flag = false; if (!s_ConfigInitialized && this.CheckForConfigLoad(this.m_String)) { InitializeUriConfig(); } this.m_iriParsing = s_IriParsing && ((this.m_Syntax == null) || this.m_Syntax.InFact(UriSyntaxFlags.AllowIriParsing)); if (this.m_iriParsing && this.CheckForUnicode(this.m_String)) { this.m_Flags |= Flags.HasUnicode; flag = true; this.m_originalUnicodeString = this.m_String; } if (this.m_Syntax != null) { if (!this.m_Syntax.IsSimple) { this.m_Syntax = this.m_Syntax.InternalOnNewUri(); this.m_Flags |= Flags.HostNotParsed | Flags.UserDrivenParsing; this.m_Syntax.InternalValidate(this, out e); if (e == null) { if ((err != ParsingError.None) || this.InFact(Flags.ErrorOrParsingRecursion)) { this.SetUserDrivenParsing(); } else if (uriKind == UriKind.Relative) { e = GetException(ParsingError.CannotCreateRelative); } if (this.m_iriParsing && flag) { this.EnsureParseRemaining(); } } else if (((uriKind != UriKind.Absolute) && (err != ParsingError.None)) && (err <= ParsingError.EmptyUriString)) { this.m_Syntax = null; e = null; this.m_Flags &= Flags.HostNotParsed | Flags.UserEscaped; } } else { if ((err = this.PrivateParseMinimal()) != ParsingError.None) { if ((uriKind != UriKind.Absolute) && (err <= ParsingError.EmptyUriString)) { this.m_Syntax = null; e = null; this.m_Flags &= Flags.HostNotParsed | Flags.UserEscaped; } else { e = GetException(err); } } else if (uriKind == UriKind.Relative) { e = GetException(ParsingError.CannotCreateRelative); } else { e = null; } if (this.m_iriParsing && flag) { this.EnsureParseRemaining(); } } } else if (((err != ParsingError.None) && (uriKind != UriKind.Absolute)) && (err <= ParsingError.EmptyUriString)) { e = null; this.m_Flags &= Flags.HasUnicode | Flags.UserEscaped; if (this.m_iriParsing && flag) { this.m_String = this.EscapeUnescapeIri(this.m_originalUnicodeString, 0, this.m_originalUnicodeString.Length, 0); try { this.m_String = this.m_String.Normalize(NormalizationForm.FormC); } catch (ArgumentException) { e = GetException(ParsingError.BadFormat); } } } else { this.m_String = null; e = GetException(err); } }
public void _InitializeAndValidate (Uri uri, out UriFormatException parsingError) { InitializeAndValidate (uri, out parsingError); }
} // 0x00000001809CC300-0x00000001809CC3A0 protected virtual string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { parsingError = default; return(default);
protected virtual new void InitializeAndValidate(Uri uri, out UriFormatException parsingError) { Contract.Requires(uri != null); parsingError = default(UriFormatException); }
protected override void InitializeAndValidate(Uri uri, out UriFormatException parsingError) { parsingError = null; }
protected virtual UriParser OnNewUri() => default; // 0x00000001802A78B0-0x00000001802A78C0 protected virtual void InitializeAndValidate(Uri uri, out UriFormatException parsingError) { parsingError = default; } // 0x00000001809CC300-0x00000001809CC3A0
} // 0x00000001809D1940-0x00000001809D1AF0 private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatException e) { e = default; } // 0x00000001809D5DC0-0x00000001809D6670
protected virtual string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { if (baseUri.UserDrivenParsing) { throw new InvalidOperationException(SR.GetString("net_uri_UserDrivenParsing", new object[] { base.GetType().FullName })); } if (!baseUri.IsAbsoluteUri) { throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute")); } string newUriString = null; bool userEscaped = false; Uri uri = Uri.ResolveHelper(baseUri, relativeUri, ref newUriString, ref userEscaped, out parsingError); if (parsingError != null) { return null; } if (uri != null) { return uri.OriginalString; } return newUriString; }
protected virtual new string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { Contract.Requires(baseUri != null); parsingError = default(UriFormatException); return default(string); }
protected override void InitializeAndValidate (Uri uri, out UriFormatException parsingError) { throw new NotImplementedException (); // base.InitializeAndValidate (uri, out parsingError); }
// // Parses and validates a Uri object, is called at the Uri ctor time. // // This method returns a non null parsingError if Uri being created is invalid: // protected virtual void InitializeAndValidate(Uri uri, out UriFormatException parsingError) { parsingError = uri.ParseMinimal(); }
// // Resolves into either baseUri or relativeUri according to conditions OR if not possible it uses newUriString // to return combined URI strings from both Uris // otherwise if e != null on output the operation has failed // internal static Uri ResolveHelper(Uri baseUri, Uri relativeUri, ref string newUriString, ref bool userEscaped, out UriFormatException e) { Debug.Assert(!baseUri.IsNotAbsoluteUri && !baseUri.UserDrivenParsing, "Uri::ResolveHelper()|baseUri is not Absolute or is controlled by User Parser."); e = null; string relativeStr = string.Empty; if ((object)relativeUri != null) { if (relativeUri.IsAbsoluteUri) return relativeUri; relativeStr = relativeUri.OriginalString; userEscaped = relativeUri.UserEscaped; } else relativeStr = string.Empty; // Here we can assert that passed "relativeUri" is indeed a relative one if (relativeStr.Length > 0 && (IsLWS(relativeStr[0]) || IsLWS(relativeStr[relativeStr.Length - 1]))) relativeStr = relativeStr.Trim(_WSchars); if (relativeStr.Length == 0) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri, baseUri.UserEscaped ? UriFormat.UriEscaped : UriFormat.SafeUnescaped); return null; } // Check for a simple fragment in relative part if (relativeStr[0] == '#' && !baseUri.IsImplicitFile && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri & ~UriComponents.Fragment, UriFormat.UriEscaped) + relativeStr; return null; } // Check for a simple query in relative part if (relativeStr[0] == '?' && !baseUri.IsImplicitFile && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveQuery)) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri & ~UriComponents.Query & ~UriComponents.Fragment, UriFormat.UriEscaped) + relativeStr; return null; } // Check on the DOS path in the relative Uri (a special case) if (relativeStr.Length >= 3 && (relativeStr[1] == ':' || relativeStr[1] == '|') && IsAsciiLetter(relativeStr[0]) && (relativeStr[2] == '\\' || relativeStr[2] == '/')) { if (baseUri.IsImplicitFile) { // It could have file:/// prepended to the result but we want to keep it as *Implicit* File Uri newUriString = relativeStr; return null; } else if (baseUri.Syntax.InFact(UriSyntaxFlags.AllowDOSPath)) { // The scheme is not changed just the path gets replaced string prefix; if (baseUri.InFact(Flags.AuthorityFound)) prefix = baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":///" : "://"; else prefix = baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":/" : ":"; newUriString = baseUri.Scheme + prefix + relativeStr; return null; } // If we are here then input like "http://host/path/" + "C:\x" will produce the result http://host/path/c:/x } ParsingError err = GetCombinedString(baseUri, relativeStr, userEscaped, ref newUriString); if (err != ParsingError.None) { e = GetException(err); return null; } if ((object)newUriString == (object)baseUri.m_String) return baseUri; return null; }
internal static Uri ResolveHelper(Uri baseUri, Uri relativeUri, ref string newUriString, ref bool userEscaped, out UriFormatException e) { e = null; string relativeStr = string.Empty; if (relativeUri != null) { if (relativeUri.IsAbsoluteUri) { return relativeUri; } relativeStr = relativeUri.OriginalString; userEscaped = relativeUri.UserEscaped; } else { relativeStr = string.Empty; } if ((relativeStr.Length > 0) && (IsLWS(relativeStr[0]) || IsLWS(relativeStr[relativeStr.Length - 1]))) { relativeStr = relativeStr.Trim(_WSchars); } if (relativeStr.Length == 0) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri, baseUri.UserEscaped ? UriFormat.UriEscaped : UriFormat.SafeUnescaped); return null; } if (((relativeStr[0] == '#') && !baseUri.IsImplicitFile) && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) { newUriString = baseUri.GetParts(UriComponents.HttpRequestUrl | UriComponents.UserInfo, UriFormat.UriEscaped) + relativeStr; return null; } if (((relativeStr[0] == '?') && !baseUri.IsImplicitFile) && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveQuery)) { newUriString = baseUri.GetParts(UriComponents.Path | UriComponents.SchemeAndServer | UriComponents.UserInfo, UriFormat.UriEscaped) + relativeStr; return null; } if (((relativeStr.Length >= 3) && ((relativeStr[1] == ':') || (relativeStr[1] == '|'))) && (IsAsciiLetter(relativeStr[0]) && ((relativeStr[2] == '\\') || (relativeStr[2] == '/')))) { if (baseUri.IsImplicitFile) { newUriString = relativeStr; return null; } if (baseUri.Syntax.InFact(UriSyntaxFlags.AllowDOSPath)) { string str2; if (baseUri.InFact(Flags.AuthorityFound)) { str2 = baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":///" : "://"; } else { str2 = baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":/" : ":"; } newUriString = baseUri.Scheme + str2 + relativeStr; return null; } } ParsingError err = GetCombinedString(baseUri, relativeStr, userEscaped, ref newUriString); if (err != ParsingError.None) { e = GetException(err); return null; } if (newUriString == baseUri.m_String) { return baseUri; } return null; }
// // a Uri.TryCreate() method goes through here. // internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e) { // if (!Enum.IsDefined(typeof(UriKind), uriKind)) -- We currently believe that Enum.IsDefined() is too slow // to be used here. if ((int)uriKind < (int)UriKind.RelativeOrAbsolute || (int)uriKind > (int)UriKind.Relative){ throw new ArgumentException(SR.GetString(SR.net_uri_InvalidUriKind, uriKind)); } UriParser syntax = null; Flags flags = Flags.Zero; ParsingError err = ParseScheme(uriString, ref flags, ref syntax); if (dontEscape) flags |= Flags.UserEscaped; // We won't use User factory for these errors if (err != ParsingError.None) { // If it looks as a relative Uri, custom factory is ignored if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) return new Uri((flags & Flags.UserEscaped), null, uriString); return null; } // Cannot be relative Uri if came here Uri result = new Uri(flags, syntax, uriString); // Validate instance using ether built in or a user Parser try { result.InitializeUri(err, uriKind, out e); if (e == null) return result; return null; } catch (UriFormatException ee) { Debug.Assert(!syntax.IsSimple, "A UriPraser threw on InitializeAndValidate."); e = ee; // A precaution since custom Parser should never throw in this case. return null; } }
protected override void InitializeAndValidate(Uri uri, out UriFormatException parsingError) { // TODO: check UIDVALIDITY, UID, SECTION, PARTIAL, etc. base.InitializeAndValidate(uri, out parsingError); }
/// <summary> /// Connects to the service to retrieve fields information. /// </summary> /// <param name="commandParameter"></param> private void OnConnect(object commandParameter) { if (!CanConnect(commandParameter)) return; try { bool savedConfiguration = commandParameter as string == Constants.SAVED_CONFIGURATION; if (!savedConfiguration) Reset(); IsBusy = true; initializedAction = (f) => { IsConnected = true; if (f == null || f.LayerInfo == null || f.LayerInfo.Fields == null) Error = new Exception(Resources.Strings.LayerInfoMissing); if (IsTable) { UseServiceRenderer = false; AutoPinResults = false; AutoZoomToResults = false; } OnPropertyChanged("QueryTitle"); OnPropertyChanged("Fields"); OnPropertyChanged("HasResults"); OnPropertyChanged("IsTable"); OnPropertyChanged("IsConnectionValid"); AddChanged(); if (!savedConfiguration) InitalizeOutFields(); else initializeExpressions(); }; var url = !ServiceUrl.StartsWith("http") ? string.Format("http://{0}", ServiceUrl) : ServiceUrl; resultLayer = new FeatureLayer() { DisableClientCaching = true, Url = url }; if (UseProxy && !string.IsNullOrEmpty(ProxyUrl)) resultLayer.ProxyUrl = ProxyUrl; // Subscribes to initialized event and initializes layer. resultLayer.InitializationFailed += ResultLayer_InitializationFailed; resultLayer.Initialized += ResultLayer_Initialized; resultLayer.Initialize(); } catch (Exception ex) { IsConnected = true; IsBusy = false; if (ex is UriFormatException) { Error = new UriFormatException(string.Format(Resources.Strings.UriFormatError, ServiceUrl), ex); } else { Error = new Exception(string.Format(Resources.Strings.UnableToAccess, ServiceUrl), ex); } } }
protected internal virtual string Resolve(System.Uri baseUri, System.Uri relativeUri, out System.UriFormatException parsingError) { throw new NotImplementedException(); }
protected virtual void InitializeAndValidate(Uri uri, out UriFormatException parsingError) { }
protected virtual string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { }
public string _Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parserError) { return base.Resolve (baseUri, relativeUri, out parserError); }
// private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatException e) { if (err == ParsingError.None) { if (IsImplicitFile) { // V1 compat VsWhidbey#252282 // A relative Uri wins over implicit UNC path unless the UNC path is of the form "\\something" and // uriKind != Absolute if ( #if !PLATFORM_UNIX NotAny(Flags.DosPath) && #endif // !PLATFORM_UNIX uriKind != UriKind.Absolute && (uriKind == UriKind.Relative || (m_String.Length >= 2 && (m_String[0] != '\\' || m_String[1] != '\\')))) { m_Syntax = null; //make it be relative Uri m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri e = null; return; // Otheriwse an absolute file Uri wins when it's of the form "\\something" } // // VsWhidbey#423805 and V1 compat issue // We should support relative Uris of the form c:\bla or c:/bla // #if !PLATFORM_UNIX else if (uriKind == UriKind.Relative && InFact(Flags.DosPath)) { m_Syntax = null; //make it be relative Uri m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri e = null; return; // Otheriwse an absolute file Uri wins when it's of the form "c:\something" } #endif // !PLATFORM_UNIX } } else if (err > ParsingError.LastRelativeUriOkErrIndex) { //This is a fatal error based solely on scheme name parsing m_String = null; // make it be invalid Uri e = GetException(err); return; } // // // bool hasUnicode = false; // Is there unicode .. if ((!s_ConfigInitialized) && CheckForConfigLoad(m_String)){ InitializeUriConfig(); } m_iriParsing = (s_IriParsing && ((m_Syntax == null) || m_Syntax.InFact(UriSyntaxFlags.AllowIriParsing))); if (m_iriParsing && (CheckForUnicode(m_String) || CheckForEscapedUnreserved(m_String))) { m_Flags |= Flags.HasUnicode; hasUnicode = true; // switch internal strings m_originalUnicodeString = m_String; // original string location changed } if (m_Syntax != null) { if (m_Syntax.IsSimple) { if ((err = PrivateParseMinimal()) != ParsingError.None) { if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { // RFC 3986 Section 5.4.2 - http:(relativeUri) may be considered a valid relative Uri. m_Syntax = null; // convert to relative uri e = null; m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri } else e = GetException(err); } else if (uriKind == UriKind.Relative) { // Here we know that we can create an absolute Uri, but the user has requested only a relative one e = GetException(ParsingError.CannotCreateRelative); } else e = null; // will return from here if (m_iriParsing && hasUnicode){ // In this scenario we need to parse the whole string EnsureParseRemaining(); } } else { // offer custom parser to create a parsing context m_Syntax = m_Syntax.InternalOnNewUri(); // incase they won't call us m_Flags |= Flags.UserDrivenParsing; // Ask a registered type to validate this uri m_Syntax.InternalValidate(this, out e); if (e != null) { // Can we still take it as a relative Uri? if (uriKind != UriKind.Absolute && err != ParsingError.None && err <= ParsingError.LastRelativeUriOkErrIndex) { m_Syntax = null; // convert it to relative e = null; m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri } } else // e == null { if (err != ParsingError.None || InFact(Flags.ErrorOrParsingRecursion)) { // User parser took over on an invalid Uri SetUserDrivenParsing(); } else if (uriKind == UriKind.Relative) { // Here we know that custom parser can create an absolute Uri, but the user has requested only a // relative one e = GetException(ParsingError.CannotCreateRelative); } if (m_iriParsing && hasUnicode){ // In this scenario we need to parse the whole string EnsureParseRemaining(); } } // will return from here } } // If we encountered any parsing errors that indicate this may be a relative Uri, // and we'll allow relative Uri's, then create one. else if (err != ParsingError.None && uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { e = null; m_Flags &= (Flags.UserEscaped | Flags.HasUnicode); // the only flags that makes sense for a relative uri if (m_iriParsing && hasUnicode) { // Iri'ze and then normalize relative uris m_String = EscapeUnescapeIri(m_originalUnicodeString, 0, m_originalUnicodeString.Length, (UriComponents)0); try { if (UriParser.ShouldUseLegacyV2Quirks) m_String = m_String.Normalize(NormalizationForm.FormC); } catch (ArgumentException) { e = GetException(ParsingError.BadFormat); } } } else { m_String = null; // make it be invalid Uri e = GetException(err); } }
protected internal virtual void InitializeAndValidate (Uri uri, out UriFormatException parsingError) { // bad boy, it should check null arguments. if ((uri.Scheme != scheme_name) && (scheme_name != "*")) // Here .NET seems to return "The Authority/Host could not be parsed", but it does not make sense. parsingError = new UriFormatException ("The argument Uri's scheme does not match"); else parsingError = null; }
protected internal virtual string Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { // used by Uri.ctor and Uri.TryCreate throw new NotImplementedException (); }
protected override string Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { return base.Resolve (baseUri, relativeUri, out parsingError); }
// private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatException e) { if (err == ParsingError.None) { if (IsImplicitFile) { // V1 compat VsWhidbey#252282 // A relative Uri wins over implicit UNC path unless the UNC path is of the form "\\something" and // uriKind != Absolute if ( #if !PLATFORM_UNIX NotAny(Flags.DosPath) && #endif // !PLATFORM_UNIX uriKind != UriKind.Absolute && (uriKind == UriKind.Relative || (m_String.Length >= 2 && (m_String[0] != '\\' || m_String[1] != '\\')))) { m_Syntax = null; //make it be relative Uri m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri e = null; return; // Otheriwse an absolute file Uri wins when it's of the form "\\something" } // // VsWhidbey#423805 and V1 compat issue // We should support relative Uris of the form c:\bla or c:/bla // #if !PLATFORM_UNIX else if (uriKind == UriKind.Relative && InFact(Flags.DosPath)) { m_Syntax = null; //make it be relative Uri m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri e = null; return; // Otheriwse an absolute file Uri wins when it's of the form "c:\something" } #endif // !PLATFORM_UNIX } } else if (err > ParsingError.LastRelativeUriOkErrIndex) { //This is a fatal error based solely on scheme name parsing m_String = null; // make it be invalid Uri e = GetException(err); return; } // // // bool hasUnicode = false; // Is there unicode .. if ((!s_ConfigInitialized) && CheckForConfigLoad(m_String)) { InitializeUriConfig(); } m_iriParsing = (s_IriParsing && ((m_Syntax == null) || m_Syntax.InFact(UriSyntaxFlags.AllowIriParsing))); if (m_iriParsing && (CheckForUnicode(m_String) || CheckForEscapedUnreserved(m_String))) { m_Flags |= Flags.HasUnicode; hasUnicode = true; // switch internal strings m_originalUnicodeString = m_String; // original string location changed } if (m_Syntax != null) { if (m_Syntax.IsSimple) { if ((err = PrivateParseMinimal()) != ParsingError.None) { if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { // RFC 3986 Section 5.4.2 - http:(relativeUri) may be considered a valid relative Uri. m_Syntax = null; // convert to relative uri e = null; m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri } else { e = GetException(err); } } else if (uriKind == UriKind.Relative) { // Here we know that we can create an absolute Uri, but the user has requested only a relative one e = GetException(ParsingError.CannotCreateRelative); } else { e = null; } // will return from here // Parse unicode and reserved characters only if we're sure that we have an absolute Uri, either because it was // specified via uriKind, or because the parsing error does not indicate that we have a relative URI. if (m_iriParsing && hasUnicode && (uriKind == UriKind.Absolute || err == ParsingError.None)) { // In this scenario we need to parse the whole string EnsureParseRemaining(); } } else { // offer custom parser to create a parsing context m_Syntax = m_Syntax.InternalOnNewUri(); // incase they won't call us m_Flags |= Flags.UserDrivenParsing; // Ask a registered type to validate this uri m_Syntax.InternalValidate(this, out e); if (e != null) { // Can we still take it as a relative Uri? if (uriKind != UriKind.Absolute && err != ParsingError.None && err <= ParsingError.LastRelativeUriOkErrIndex) { m_Syntax = null; // convert it to relative e = null; m_Flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri } } else // e == null { if (err != ParsingError.None || InFact(Flags.ErrorOrParsingRecursion)) { // User parser took over on an invalid Uri SetUserDrivenParsing(); } else if (uriKind == UriKind.Relative) { // Here we know that custom parser can create an absolute Uri, but the user has requested only a // relative one e = GetException(ParsingError.CannotCreateRelative); } if (m_iriParsing && hasUnicode) { // In this scenario we need to parse the whole string EnsureParseRemaining(); } } // will return from here } } // If we encountered any parsing errors that indicate this may be a relative Uri, // and we'll allow relative Uri's, then create one. else if (err != ParsingError.None && uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { e = null; m_Flags &= (Flags.UserEscaped | Flags.HasUnicode); // the only flags that makes sense for a relative uri if (m_iriParsing && hasUnicode) { // Iri'ze and then normalize relative uris m_String = EscapeUnescapeIri(m_originalUnicodeString, 0, m_originalUnicodeString.Length, (UriComponents)0); try { if (UriParser.ShouldUseLegacyV2Quirks) { m_String = m_String.Normalize(NormalizationForm.FormC); } } catch (ArgumentException) { e = GetException(ParsingError.BadFormat); } } } else { m_String = null; // make it be invalid Uri e = GetException(err); } }
internal string InternalResolve(Uri thisBaseUri, Uri uriLink, out UriFormatException parsingError) { return(Resolve(thisBaseUri, uriLink, out parsingError)); }
private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatException e) { if (err == ParsingError.None) { if (IsImplicitFile) { // V1 compat // A relative Uri wins over implicit UNC path unless the UNC path is of the form "\\something" and // uriKind != Absolute if (NotAny(Flags.DosPath) && uriKind != UriKind.Absolute && (uriKind == UriKind.Relative || (_string.Length >= 2 && (_string[0] != '\\' || _string[1] != '\\')))) { _syntax = null; //make it be relative Uri _flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri e = null; return; // Otheriwse an absolute file Uri wins when it's of the form "\\something" } // // V1 compat issue // We should support relative Uris of the form c:\bla or c:/bla // else if (uriKind == UriKind.Relative && InFact(Flags.DosPath)) { _syntax = null; //make it be relative Uri _flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri e = null; return; // Otheriwse an absolute file Uri wins when it's of the form "c:\something" } } } else if (err > ParsingError.LastRelativeUriOkErrIndex) { //This is a fatal error based solely on scheme name parsing _string = null; // make it be invalid Uri e = GetException(err); return; } bool hasUnicode = false; _iriParsing = (s_IriParsing && ((_syntax == null) || _syntax.InFact(UriSyntaxFlags.AllowIriParsing))); if (_iriParsing && (CheckForUnicode(_string) || CheckForEscapedUnreserved(_string))) { _flags |= Flags.HasUnicode; hasUnicode = true; // switch internal strings _originalUnicodeString = _string; // original string location changed } if (_syntax != null) { if (_syntax.IsSimple) { if ((err = PrivateParseMinimal()) != ParsingError.None) { if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { // RFC 3986 Section 5.4.2 - http:(relativeUri) may be considered a valid relative Uri. _syntax = null; // convert to relative uri e = null; _flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri } else { e = GetException(err); } } else if (uriKind == UriKind.Relative) { // Here we know that we can create an absolute Uri, but the user has requested only a relative one e = GetException(ParsingError.CannotCreateRelative); } else { e = null; } // will return from here if (_iriParsing && hasUnicode) { // In this scenario we need to parse the whole string EnsureParseRemaining(); } } else { // offer custom parser to create a parsing context _syntax = _syntax.InternalOnNewUri(); // incase they won't call us _flags |= Flags.UserDrivenParsing; // Ask a registered type to validate this uri _syntax.InternalValidate(this, out e); if (e != null) { // Can we still take it as a relative Uri? if (uriKind != UriKind.Absolute && err != ParsingError.None && err <= ParsingError.LastRelativeUriOkErrIndex) { _syntax = null; // convert it to relative e = null; _flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri } } else // e == null { if (err != ParsingError.None || InFact(Flags.ErrorOrParsingRecursion)) { // User parser took over on an invalid Uri SetUserDrivenParsing(); } else if (uriKind == UriKind.Relative) { // Here we know that custom parser can create an absolute Uri, but the user has requested only a // relative one e = GetException(ParsingError.CannotCreateRelative); } if (_iriParsing && hasUnicode) { // In this scenario we need to parse the whole string EnsureParseRemaining(); } } // will return from here } } // If we encountered any parsing errors that indicate this may be a relative Uri, // and we'll allow relative Uri's, then create one. else if (err != ParsingError.None && uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex) { e = null; _flags &= (Flags.UserEscaped | Flags.HasUnicode); // the only flags that makes sense for a relative uri if (_iriParsing && hasUnicode) { // Iri'ze and then normalize relative uris _string = EscapeUnescapeIri(_originalUnicodeString, 0, _originalUnicodeString.Length, (UriComponents)0); } } else { _string = null; // make it be invalid Uri e = GetException(err); } }
internal string InternalResolve(Uri thisBaseUri, Uri uriLink, out UriFormatException parsingError) { return Resolve(thisBaseUri, uriLink, out parsingError); }
// // Resolves into either baseUri or relativeUri according to conditions OR if not possible it uses newUriString // to return combined URI strings from both Uris // otherwise if e != null on output the operation has failed // internal static Uri ResolveHelper(Uri baseUri, Uri relativeUri, ref string newUriString, ref bool userEscaped, out UriFormatException e) { Debug.Assert(!baseUri.IsNotAbsoluteUri && !baseUri.UserDrivenParsing, "Uri::ResolveHelper()|baseUri is not Absolute or is controlled by User Parser."); e = null; string relativeStr = string.Empty; if ((object)relativeUri != null) { if (relativeUri.IsAbsoluteUri) { return(relativeUri); } relativeStr = relativeUri.OriginalString; userEscaped = relativeUri.UserEscaped; } else { relativeStr = string.Empty; } // Here we can assert that passed "relativeUri" is indeed a relative one if (relativeStr.Length > 0 && (IsLWS(relativeStr[0]) || IsLWS(relativeStr[relativeStr.Length - 1]))) { relativeStr = relativeStr.Trim(s_WSchars); } if (relativeStr.Length == 0) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri, baseUri.UserEscaped ? UriFormat.UriEscaped : UriFormat.SafeUnescaped); return(null); } // Check for a simple fragment in relative part if (relativeStr[0] == '#' && !baseUri.IsImplicitFile && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri & ~UriComponents.Fragment, UriFormat.UriEscaped) + relativeStr; return(null); } // Check for a simple query in relative part if (relativeStr[0] == '?' && !baseUri.IsImplicitFile && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveQuery)) { newUriString = baseUri.GetParts(UriComponents.AbsoluteUri & ~UriComponents.Query & ~UriComponents.Fragment, UriFormat.UriEscaped) + relativeStr; return(null); } // Check on the DOS path in the relative Uri (a special case) if (relativeStr.Length >= 3 && (relativeStr[1] == ':' || relativeStr[1] == '|') && IsAsciiLetter(relativeStr[0]) && (relativeStr[2] == '\\' || relativeStr[2] == '/')) { if (baseUri.IsImplicitFile) { // It could have file:/// prepended to the result but we want to keep it as *Implicit* File Uri newUriString = relativeStr; return(null); } else if (baseUri.Syntax.InFact(UriSyntaxFlags.AllowDOSPath)) { // The scheme is not changed just the path gets replaced string prefix; if (baseUri.InFact(Flags.AuthorityFound)) { prefix = baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":///" : "://"; } else { prefix = baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":/" : ":"; } newUriString = baseUri.Scheme + prefix + relativeStr; return(null); } // If we are here then input like "http://host/path/" + "C:\x" will produce the result http://host/path/c:/x } ParsingError err = GetCombinedString(baseUri, relativeStr, userEscaped, ref newUriString); if (err != ParsingError.None) { e = GetException(err); return(null); } if ((object)newUriString == (object)baseUri._string) { return(baseUri); } return(null); }
internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e) { if ((uriKind < UriKind.RelativeOrAbsolute) || (uriKind > UriKind.Relative)) { throw new ArgumentException(System.SR.GetString("net_uri_InvalidUriKind", new object[] { uriKind })); } UriParser syntax = null; Flags hostNotParsed = Flags.HostNotParsed; ParsingError err = ParseScheme(uriString, ref hostNotParsed, ref syntax); if (dontEscape) { hostNotParsed |= Flags.HostNotParsed | Flags.UserEscaped; } if (err != ParsingError.None) { if ((uriKind != UriKind.Absolute) && (err <= ParsingError.EmptyUriString)) { return new Uri(hostNotParsed & (Flags.HostNotParsed | Flags.UserEscaped), null, uriString); } return null; } Uri uri = new Uri(hostNotParsed, syntax, uriString); try { uri.InitializeUri(err, uriKind, out e); if (e == null) { return uri; } return null; } catch (UriFormatException exception) { e = exception; return null; } }
protected override string Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parsingError) { throw new OutOfMemoryException (); // return base.Resolve (baseUri, relativeUri, out parsingError); }
public void DenyUnrestricted () { // can we call everything without a SecurityException ? UriFormatException ufe = new UriFormatException (); }