<changes>
<release version="3.8-beta4" date="2011-??-??">
+ <action dev="poi-developers" type="fix">51187 - fixed OPCPackage to correctly handle self references</action>
<action dev="poi-developers" type="fix">51635 - Improved performance of XSSFSheet#write</action>
<action dev="poi-developers" type="fix">47731 - Word Extractor considers text copied from some website as an embedded object</action>
<action dev="poi-developers" type="add">Add Word-to-Text converter and use it as replacement for WordExtractor</action>
// Special case for where the two are the same
if (segmentsTheSame == segmentsSource.length
&& segmentsTheSame == segmentsTarget.length) {
- retVal.append("");
+ if(sourceURI.equals(targetURI)){
+ // if source and target are the same they should be resolved to the last segment,
+ // Example: if a slide references itself, e.g. the source URI is
+ // "/ppt/slides/slide1.xml" and the targetURI is "slide1.xml" then
+ // this it should be relativized as "slide1.xml", i.e. the last segment.
+ retVal.append(segmentsSource[segmentsSource.length - 1]);
+ } else {
+ retVal.append("");
+ }
+
} else {
// Matched for so long, but no more
// Document to itself is the same place (empty URI)
URI retURI2 = PackagingURIHelper.relativizeURI(uri1, uri1);
- assertEquals("", retURI2.getPath());
+ // YK: the line below used to assert empty string which is wrong
+ // if source and target are the same they should be relaitivized as the last segment,
+ // see Bugzilla 51187
+ assertEquals("document.xml", retURI2.getPath());
// relativization against root
URI root = new URI("/");
assertEquals("'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A5", rel6.getFragment());
}
+ public void testSelfRelations_bug51187() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OPCPackage pkg = OPCPackage.create(baos);
+
+ PackagePart partA =
+ pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain");
+ assertNotNull(partA);
+
+ // reference itself
+ PackageRelationship rel1 = partA.addRelationship(partA.getPartName(), TargetMode.INTERNAL, "partA");
+
+
+ // Save, and re-load
+ pkg.close();
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ pkg = OPCPackage.open(bais);
+
+ partA = pkg.getPart(PackagingURIHelper.createPartName("/partA"));
+
+
+ // Check the relations
+ assertEquals(1, partA.getRelationships().size());
+
+ PackageRelationship rel2 = partA.getRelationships().getRelationship(0);
+
+ assertEquals(rel1.getRelationshipType(), rel2.getRelationshipType());
+ assertEquals(rel1.getId(), rel2.getId());
+ assertEquals(rel1.getSourceURI(), rel2.getSourceURI());
+ assertEquals(rel1.getTargetURI(), rel2.getTargetURI());
+ assertEquals(rel1.getTargetMode(), rel2.getTargetMode());
+ }
}
assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
// TODO Fix this
-// assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
+ assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
}
}