Skip to content

Commit

Permalink
Merge pull request mono#476 from pruiz/xamarin-bug-2527
Browse files Browse the repository at this point in the history
Fix implementation of System.IO.Packaging::GetRelativeUri(Uri,Uri) [fixes xamarin's bug mono#2727]
  • Loading branch information
marek-safar committed Oct 13, 2012
2 parents e2e63b7 + fe99400 commit 8298b36
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions mcs/class/WindowsBase/System.IO.Packaging/Check.cs
Expand Up @@ -135,6 +135,12 @@ public static void SourcePartUri (Uri sourcePartUri)
{
NotNull(sourcePartUri, "sourcePartUri");
}

public static void TargetPartUri (Uri targetPartUri)
{
NotNull(targetPartUri, "targetPartUri");
}

public static void SourceUri (Uri sourceUri)
{
if (sourceUri == null)
Expand Down
10 changes: 7 additions & 3 deletions mcs/class/WindowsBase/System.IO.Packaging/PackUriHelper.cs
Expand Up @@ -139,10 +139,14 @@ public static Uri GetRelationshipPartUri (Uri partUri)

public static Uri GetRelativeUri (Uri sourcePartUri, Uri targetPartUri)
{
//Check.SourcePartUri (sourcePartUri);
//Check.TargetPartUri (targetPartUri);
Check.SourcePartUri (sourcePartUri);
Check.TargetPartUri (targetPartUri);

Uri uri = new Uri ("http://fake.com");
Uri a = new Uri (uri, sourcePartUri.AbsolutePath);
Uri b = new Uri (uri, targetPartUri.AbsolutePath);

return sourcePartUri;
return a.MakeRelativeUri(b);
}

public static Uri GetSourcePartUriFromRelationshipPartUri (Uri relationshipPartUri)
Expand Down
Expand Up @@ -230,6 +230,21 @@ public void GetRelativeUriTest ()

dest = new Uri ("/1/2/", UriKind.Relative);
Assert.AreEqual (new Uri ("", UriKind.Relative), PackUriHelper.GetRelativeUri (src, src), "#4");

// See: http://msdn.microsoft.com/en-us/library/system.io.packaging.packurihelper.getrelativeuri.aspx

src = new Uri("/mydoc/markup/page.xml", UriKind.Relative);
dest = new Uri("/mydoc/markup/picture.jpg", UriKind.Relative);
Assert.AreEqual (new Uri ("picture.jpg", UriKind.Relative), PackUriHelper.GetRelativeUri (src, dest), "#5");

src = new Uri("/mydoc/markup/page.xml", UriKind.Relative);
dest = new Uri("/mydoc/picture.jpg", UriKind.Relative);
Assert.AreEqual (new Uri ("../picture.jpg", UriKind.Relative), PackUriHelper.GetRelativeUri (src, dest), "#6");

src = new Uri("/mydoc/markup/page.xml", UriKind.Relative);
dest = new Uri("/mydoc/images/picture.jpg", UriKind.Relative);
Assert.AreEqual (new Uri ("../images/picture.jpg", UriKind.Relative), PackUriHelper.GetRelativeUri (src, dest), "#7");

}

[Test]
Expand Down Expand Up @@ -299,4 +314,4 @@ public void ResolvePartUri4 ()
Assert.AreEqual ("/word/document.xml", result.ToString(), "#2");
}
}
}
}

0 comments on commit 8298b36

Please sign in to comment.