Skip to content

Commit

Permalink
(constructor): Properly implement RFC 2396, Par. 5.2,
Browse files Browse the repository at this point in the history
part 6a.

This fixes bug #45614.

svn path=/trunk/mcs/; revision=17304
  • Loading branch information
Duncan Mak committed Aug 13, 2003
1 parent cbf8ff8 commit deb01b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 14 additions & 0 deletions mcs/class/System/System/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2003-08-12 Duncan Mak <duncan@ximian.com>

* Uri.cs (constructor): Properly implement RFC 2396, Par. 5.2,
part 6a, which says:

In other words, any characters after the last (right-most)
slash character, if any, are excluded.

Previously, when merging "a://foo.com/foo" with "bar", we yield
the result "a://foo.com/foobar", instead of the correct
"a://foo.com/bar".

This fixes bug #45614.

2003-07-27 Andreas Nahr <ClassDevelopment@A-SoftTech.com>

* SRDescriptionAttribute.cs: Moved from System.Diagnostics directory
Expand Down
15 changes: 8 additions & 7 deletions mcs/class/System/System/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ public Uri (Uri baseUri, string relativeUri, bool dontEscape)
this.fragment = baseUri.fragment;
return;
}

int pos = relativeUri.IndexOf (':');
if (pos != -1) {

int pos2 = relativeUri.IndexOfAny (new char [] {'/', '\\'});

if (pos2 > pos) {
// equivalent to new Uri (relativeUri, dontEscape)
Parse (relativeUri);
Expand All @@ -132,7 +134,7 @@ public Uri (Uri baseUri, string relativeUri, bool dontEscape)
return;
}
}

// 8 fragment
pos = relativeUri.IndexOf ('#');
if (pos != -1) {
Expand All @@ -151,7 +153,7 @@ public Uri (Uri baseUri, string relativeUri, bool dontEscape)
relativeUri = relativeUri.Substring (0, pos);
}

if (relativeUri[0] == '/') {
if (relativeUri [0] == '/') {
path = relativeUri;
if (!userEscaped)
path = EscapeString (path);
Expand All @@ -161,12 +163,12 @@ public Uri (Uri baseUri, string relativeUri, bool dontEscape)
// par 5.2 step 6 a)
path = baseUri.path;
pos = path.LastIndexOf ('/');
if (pos > 0)
if (pos >= 0)
path = path.Substring (0, pos + 1);

// 6 b)
path += relativeUri;

// 6 c)
int startIndex = 0;
while (true) {
Expand Down Expand Up @@ -211,7 +213,6 @@ public Uri (Uri baseUri, string relativeUri, bool dontEscape)
// 6 f)
if (path.Length > 3 && path.EndsWith ("/..")) {
pos = path.LastIndexOf ('/', path.Length - 4);
Console.WriteLine ("6f " + pos);
if (pos != -1)
if (path.Substring (pos + 1, path.Length - pos - 4) != "..")
path = path.Remove (pos + 1, path.Length - pos - 1);
Expand Down

0 comments on commit deb01b6

Please sign in to comment.