static Uri ()
{
-#if NET_4_5
IriParsing = true;
-#endif
var iriparsingVar = Environment.GetEnvironmentVariable ("MONO_URI_IRIPARSING");
if (iriparsingVar == "true")
success = false;
break;
}
+
+ if (success && host.Length > 1 && host [0] != '[' && host [host.Length - 1] != ']') {
+ // host name present (but not an IPv6 address)
+ host = host.ToLower (CultureInfo.InvariantCulture);
+ }
}
}
}
} else {
path = baseEl.path;
-#if !NET_4_0
- if (relativeEl.query != null) {
- var pathEnd = path.LastIndexOf ('/');
- path = (pathEnd > 0)? path.Substring (0, pathEnd+1) : "";
- }
-#endif
}
if ((path.Length == 0 || path [0] != '/') && baseEl.delimiter == SchemeDelimiter)
//
public Uri MakeRelativeUri (Uri uri)
{
-#if NET_4_0
if (uri == null)
throw new ArgumentNullException ("uri");
-#endif
if (Host != uri.Host || Scheme != uri.Scheme)
return uri;
{
Parse (kind, source);
- if (userEscaped)
- return;
-
if (host.Length > 1 && host [0] != '[' && host [host.Length - 1] != ']') {
// host name present (but not an IPv6 address)
host = host.ToLower (CultureInfo.InvariantCulture);
private UriParser Parser {
get {
if (parser == null) {
- parser = UriParser.GetParser (Scheme);
+ parser = UriParser.GetParser (scheme);
// no specific parser ? then use a default one
if (parser == null)
parser = new DefaultUriParser ("*");
public string GetComponents (UriComponents components, UriFormat format)
{
+ if ((components & UriComponents.SerializationInfoString) == 0)
+ EnsureAbsoluteUri ();
+
return Parser.GetComponents (this, components, format);
}
public bool IsBaseOf (Uri uri)
{
-#if NET_4_0
if (uri == null)
throw new ArgumentNullException ("uri");
-#endif
return Parser.IsBaseOf (this, uri);
}
if ((uri1 == null) && (uri2 == null))
return 0;
+ if (uri1 == null)
+ return -1;
+ if (uri2 == null)
+ return 1;
string s1 = uri1.GetComponents (partsToCompare, compareFormat);
string s2 = uri2.GetComponents (partsToCompare, compareFormat);
return false;
}
-#if !NET_4_5
- switch (b) {
- case '!':
- case '\'':
- case '(':
- case ')':
- case '*':
- case '-':
- case '.':
- return false;
- }
-#endif
return true;
}
case '_':
case '~':
return false;
-#if NET_4_5
case '[':
case ']':
return false;
-#endif
}
return true;
result = null;
if ((baseUri == null) || !baseUri.IsAbsoluteUri)
return false;
-#if NET_4_0
if (relativeUri == null)
return false;
-#endif
try {
// FIXME: this should call UriParser.Resolve
result = new Uri (baseUri, relativeUri.OriginalString);
Assert.IsTrue (Uri.TryCreate ("http://mono-project.com/☕", UriKind.Absolute, out uri), "highunicode-Absolute");
Assert.AreEqual("http://mono-project.com/%E2%98%95", uri.AbsoluteUri, "highunicode-Absolute-AbsoluteUri");
+
+ string mixedCaseUri = "http://mOnO-proJECT.com";
+ uri = new Uri (mixedCaseUri);
+ Uri uri2;
+ Assert.IsTrue (Uri.TryCreate (mixedCaseUri, UriKind.Absolute, out uri2), "mixedcasehost-absolute");
+ Assert.AreEqual (uri.AbsoluteUri, uri2.AbsoluteUri, "mixedcasehost-absoluteuri-absoluteuri");
}
[Test] // TryCreate (String, UriKind, Uri)
Uri u2 = null;
Assert.AreEqual (0, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "null-null");
+ u1 = new Uri ("http://www.go-mono.com");
+ Assert.AreEqual (1, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "non-null - null");
+
+ u1 = null;
+ u2 = new Uri ("http://www.go-mono.com");
+ Assert.AreEqual (-1, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.UriEscaped, StringComparison.CurrentCulture), "null - non-null");
+
u1 = new Uri ("http://www.go-mono.com/Main Page");
u2 = new Uri ("http://www.go-mono.com/Main%20Page");
Assert.AreEqual (0, Uri.Compare (u1, u2, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.CurrentCulture), "http/space-http/%20-unescaped");
http.IsBaseOf (null);
Assert.Fail ();
}
-#if NET_4_0
catch (ArgumentNullException) {
}
-#else
- catch (NullReferenceException) {
- }
-#endif
}
[Test]