Bug 6602 - PackagePart.LoadRelationships makes relative PakcageRelationship target uris absolute
Summary: PackagePart.LoadRelationships makes relative PakcageRelationship target uris ...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WindowsBase (show other bugs)
Version: 2.10.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-08-19 13:29 UTC by Tester
Modified: 2015-09-29 18:53 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Tester 2012-08-19 13:29:52 UTC
WindowsBase.dll library's System.IO.Packaging.PackagePart.LoadRelationships(Dictionary<string, PackageRelationship> relationships, Stream stream) method appends "/" to the beginning of relationship's target uri. I'm not 100% certain this is a bug, but this appending breaks EPPlus (http://epplus.codeplex.com/) excel's xlsx file parser, that works perfectly on Microsoft's .Net. The failing code is this:				

PackagePart part; // excel sheet part
PackageRelationship sheetRelation = part.GetRelationship(...);
Uri uriWorksheet = PackUriHelper.ResolvePartUri(workbookUri, sheetRelation.TargetUri);

In the above case workbookUri is "/xl/workbook.xml" and sheetRelation.TargetUri is "/worksheets/sheet1.xml", and ResolvePartUri method returns the wrong result: "/worksheets/sheet1.xml". But if "/" wouldn't have been appended, TargetUri would be "worksheets/sheet1.xml", and ResolvePartUri would return correct result: "/xl/worksheets/sheet1.xml".

Since http://msdn.microsoft.com/en-us/library/system.io.packaging.packagerelationship.targeturi.aspx mentions that TargetUri is a relative uri, I think appending "/" is a bug.
Comment 1 Pablo Ruiz García 2012-10-14 04:14:14 UTC
I just sent a pull-request fixing this issue: https://github.com/mono/mono/pull/478

Hope it helps.
Comment 2 Eric Lawrence 2012-10-19 11:29:27 UTC
I have the following code:

using (Package oZip = Package.Open(sFilename, FileMode.Create)
{
  string sBaseURI = @"./raw/";
  Uri uriFirst = PackUriHelper.CreatePartUri(new Uri(sBaseURI + "file1.txt", UriKind.Relative));
  PackagePart oPart = oZip.CreatePart(uriFirst, "text/plain", CompressionOption.Normal);
  using (Stream strmWirteTo = oPart.GetStream()){
    // Write the file
  }
}

On Windows, this works fine, and the ZIP archive has a subfolder named "Raw".

On Mac, this code runs, but the resultant ZIP file does not show a Raw subfolder either on Mac or Windows. That's because the PackUri helper ends up converting the URI into /./raw/ which is an illegal folder name.

Does your patch fix this too?

thanks!
Comment 3 Maury Markowitz 2015-09-29 18:53:36 UTC
Having the same problem here, although it took me a while to figure out what was going on (the debugger was breaking on the wrong line for some reason).

This causes problems when you feed the Uris into PackUriHelper.ResolvePartUri, which then raises.

I solved it for now with:

    Uri PartUri;
    if (PackRel.TargetUri.IsAbsoluteUri) {
        PartUri = PackUriHelper.ResolvePartUri(PackRel.SourceUri, new Uri(PackRel.TargetUri.AbsolutePath, UriKind.Relative));
    } else {
        PartUri = PackUriHelper.ResolvePartUri(PackRel.SourceUri, PackRel.TargetUri);
    }

Note You need to log in before you can comment on or make changes to this bug.