X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FSystem%2FUri.cs;h=5749967985ba77c32e188d7205f53bc06ff7eecf;hb=c4508573a962d7e9ea34daf2b4fdb48b4e4c3e44;hp=d57cb679c6cf7b3e32b34af95c38b6e707899b56;hpb=8bb9b4409d3f73fdf5ec2afc3b9add6bd33f712f;p=mono.git diff --git a/mcs/class/System/System/Uri.cs b/mcs/class/System/System/Uri.cs index d57cb679c6c..5749967985b 100644 --- a/mcs/class/System/System/Uri.cs +++ b/mcs/class/System/System/Uri.cs @@ -90,10 +90,25 @@ namespace System { private string cachedToString; private string cachedLocalPath; private int cachedHashCode; + +#if NET_4_5 + private static volatile bool s_IriParsing = true; +#else + private static volatile bool s_IriParsing = false; +#endif + public static bool IriParsing { + get { return s_IriParsing; } + set { s_IriParsing = value; } + } + +#if BOOTSTRAP_BASIC private static readonly string hexUpperChars = "0123456789ABCDEF"; private static readonly string [] Empty = new string [0]; private static bool isWin32 = (Path.DirectorySeparatorChar == '\\'); +#else + static readonly char[] hexUpperChars = new [] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; +#endif // Fields @@ -108,7 +123,11 @@ namespace System { public static readonly string UriSchemeNntp = "nntp"; public static readonly string UriSchemeNetPipe = "net.pipe"; public static readonly string UriSchemeNetTcp = "net.tcp"; - + + internal static readonly string UriSchemeTelnet = "telnet"; + internal static readonly string UriSchemeLdap = "ldap"; + internal static readonly string UriSchemeUuid = "uuid"; + private static readonly string [] knownUriSchemes = { UriSchemeFile, @@ -125,15 +144,10 @@ namespace System { // Constructors -#if MOONLIGHT - public Uri (string uriString) : this (uriString, UriKind.Absolute) - { - } -#else public Uri (string uriString) : this (uriString, false) { } -#endif + protected Uri (SerializationInfo serializationInfo, StreamingContext streamingContext) { string uri = serializationInfo.GetString ("AbsoluteUri"); @@ -214,6 +228,9 @@ namespace System { success = false; break; } + + if (success && isAbsoluteUri && (path.Length > 0)) + path = EscapeString (path); } } @@ -339,7 +356,7 @@ namespace System { query = relativeUri.Substring (pos); if (!userEscaped) query = EscapeString (query); -#if !NET_4_0 && !MOONLIGHT && !MOBILE +#if !NET_4_0 && !MOBILE consider_query = query.Length > 0; #endif relativeUri = pos == 0 ? String.Empty : relativeUri.Substring (0, pos); @@ -461,13 +478,10 @@ namespace System { public string AbsoluteUri { get { EnsureAbsoluteUri (); - if (cachedAbsoluteUri == null) { - cachedAbsoluteUri = GetLeftPart (UriPartial.Path); - if (query.Length > 0) - cachedAbsoluteUri += query; - if (fragment.Length > 0) - cachedAbsoluteUri += fragment; - } + + if (cachedAbsoluteUri == null) + cachedAbsoluteUri = GetComponents (UriComponents.AbsoluteUri, UriFormat.UriEscaped); + return cachedAbsoluteUri; } } @@ -648,7 +662,11 @@ namespace System { // return a (pre-allocated) empty array if (path.Length == 0) +#if BOOTSTRAP_BASIC return Empty; +#else + return EmptyArray.Value; +#endif // do not return the original array (since items can be changed) if (segments != null) return segments.ToArray (); @@ -1015,7 +1033,7 @@ namespace System { // public Uri MakeRelativeUri (Uri uri) { -#if NET_4_0 || MOONLIGHT || MOBILE +#if NET_4_0 if (uri == null) throw new ArgumentNullException ("uri"); #endif @@ -1089,13 +1107,10 @@ namespace System { if (cachedToString != null) return cachedToString; - if (isAbsoluteUri) { - cachedToString = Unescape (GetLeftPart (UriPartial.Path), true); - AppendQueryAndFragment (ref cachedToString); - } else { - // Everything is contained in path in this case. - cachedToString = path; - } + if (isAbsoluteUri) + cachedToString = parser.GetComponentsHelper (this, UriComponents.AbsoluteUri, UriHelper.ToStringUnescape); + else + cachedToString = UriHelper.FormatRelative (source, scheme, UriHelper.ToStringUnescape); return cachedToString; } @@ -1124,12 +1139,8 @@ namespace System { path = EscapeString (path); } -#if MOONLIGHT - static string EscapeString (string str) -#else [Obsolete] protected static string EscapeString (string str) -#endif { return EscapeString (str, Uri.EscapeCommonHexBrackets); } @@ -1225,12 +1236,8 @@ namespace System { path = EscapeString (path); } -#if MOONLIGHT - string Unescape (string path) -#else [Obsolete] protected virtual string Unescape (string path) -#endif { return Unescape (path, false, false); } @@ -1356,7 +1363,7 @@ namespace System { private bool SupportsQuery () { - return ((scheme != Uri.UriSchemeNntp) && (scheme != Uri.UriSchemeFtp) && (scheme != Uri.UriSchemeFile)); + return UriHelper.SupportsQuery (scheme); } // @@ -1393,12 +1400,8 @@ namespace System { if (uriString [0] == '/' && Path.DirectorySeparatorChar == '/'){ //Unix Path ParseAsUnixAbsoluteFilePath (uriString); -#if MOONLIGHT - isAbsoluteUri = false; -#else if (kind == UriKind.Relative) isAbsoluteUri = false; -#endif return null; } else if (uriString.Length >= 2 && uriString [0] == '\\' && uriString [1] == '\\') { //Windows UNC @@ -1449,6 +1452,10 @@ namespace System { scheme = TryGetKnownUriSchemeInstance (scheme); + var formatFlags = UriHelper.FormatFlags.None; + if (UriHelper.HasCharactersToNormalize (uriString)) + formatFlags |= UriHelper.FormatFlags.HasUriCharactersToNormalize; + // from here we're practically working on uriString.Substring(startpos,endpos-startpos) int startpos = pos + 1; int endpos = uriString.Length; @@ -1456,12 +1463,12 @@ namespace System { // 8 fragment pos = uriString.IndexOf ('#', startpos); if (!IsUnc && pos != -1) { - if (userEscaped) - fragment = uriString.Substring (pos); - else - fragment = "#" + EscapeString (uriString.Substring (pos+1)); - + fragment = uriString.Substring (pos); endpos = pos; + if (!userEscaped) { + fragment = "#" + UriHelper.FormatAbsolute(fragment.Substring (1), scheme, + UriComponents.Fragment, UriFormat.UriEscaped, formatFlags); + } } // special case: there is no query part for 'news' @@ -1478,8 +1485,10 @@ namespace System { if (pos != -1) { query = uriString.Substring (pos, endpos-pos); endpos = pos; - if (!userEscaped) - query = EscapeString (query); + if (!userEscaped){ + query = "?" + UriHelper.FormatAbsolute(query.Substring (1), scheme, + UriComponents.Query, UriFormat.UriEscaped, formatFlags); + } } } @@ -1612,7 +1621,11 @@ namespace System { host = String.Empty; } else if (scheme == UriSchemeFile) { // under Windows all file:// URI are considered UNC, which is not the case other MacOS (e.g. Silverlight) +#if BOOTSTRAP_BASIC isUnc = isWin32; +#else + isUnc = Environment.IsRunningOnWindows; +#endif } else if (host.Length == 0 && (scheme == UriSchemeHttp || scheme == UriSchemeGopher || scheme == UriSchemeNntp || scheme == UriSchemeHttps || scheme == UriSchemeFtp)) { @@ -1782,7 +1795,7 @@ namespace System { // A variant of HexUnescape() which can decode multi-byte escaped // sequences such as (e.g.) %E3%81%8B into a single character - private static char HexUnescapeMultiByte (string pattern, ref int index, out char surrogate) + internal static char HexUnescapeMultiByte (string pattern, ref int index, out char surrogate) { surrogate = char.MinValue; @@ -2036,7 +2049,7 @@ namespace System { public bool IsBaseOf (Uri uri) { -#if NET_4_0 || MOONLIGHT || MOBILE +#if NET_4_0 if (uri == null) throw new ArgumentNullException ("uri"); #endif @@ -2230,7 +2243,7 @@ namespace System { result = null; if ((baseUri == null) || !baseUri.IsAbsoluteUri) return false; -#if NET_4_0 || MOONLIGHT || MOBILE +#if NET_4_0 if (relativeUri == null) return false; #endif