8146606: Catalog.matchSystem() appends an extra '/' to the matched result
Reviewed-by: lancea
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteSystem.java Tue Jan 12 15:29:21 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteSystem.java Wed Jan 13 10:12:39 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -72,6 +72,7 @@
public String getSystemIdStartString () {
return systemIdStartString;
}
+
/**
* Get the rewritePrefix attribute.
* @return The rewritePrefix attribute value.
@@ -80,7 +81,6 @@
return rewritePrefix;
}
-
/**
* Try to match the specified systemId with the entry. Return the match if it
* is successful and the length of the systemIdStartString is longer than the
@@ -91,14 +91,20 @@
* @return The replacement URI if the match is successful, null if not.
*/
public String match(String systemId, int currentMatch) {
- if (systemIdStartString.length() <= systemId.length() &&
+ if (systemIdStartString.length() < systemId.length() &&
systemIdStartString.equals(systemId.substring(0, systemIdStartString.length()))) {
if (currentMatch < systemIdStartString.length()) {
String prefix = rewritePrefix.toExternalForm();
- if (!prefix.endsWith(SLASH) && !systemId.startsWith(SLASH)) {
- return prefix + SLASH + systemId.substring(systemIdStartString.length());
+ String sysId;
+ if (systemIdStartString.endsWith(SLASH)) {
+ sysId = systemId.substring(systemIdStartString.length());
} else {
- return prefix + systemId.substring(systemIdStartString.length());
+ sysId = systemId.substring(systemIdStartString.length() + 1);
+ }
+ if (prefix.endsWith(SLASH)) {
+ return prefix + sysId;
+ } else {
+ return prefix + SLASH + sysId;
}
}
}
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteUri.java Tue Jan 12 15:29:21 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteUri.java Wed Jan 13 10:12:39 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -72,6 +72,7 @@
public String getURIStartString () {
return uriStartString;
}
+
/**
* Get the rewritePrefix attribute.
* @return The rewritePrefix attribute value.
@@ -91,14 +92,20 @@
*/
@Override
public String match(String systemId, int currentMatch) {
- if (uriStartString.length() <= systemId.length() &&
+ if (uriStartString.length() < systemId.length() &&
uriStartString.equals(systemId.substring(0, uriStartString.length()))) {
if (currentMatch < uriStartString.length()) {
String prefix = rewritePrefix.toExternalForm();
- if (!prefix.endsWith(SLASH) && !systemId.startsWith(SLASH)) {
- return prefix + SLASH + systemId.substring(uriStartString.length());
+ String sysId;
+ if (uriStartString.endsWith(SLASH)) {
+ sysId = systemId.substring(uriStartString.length());
} else {
- return prefix + systemId.substring(uriStartString.length());
+ sysId = systemId.substring(uriStartString.length() + 1);
+ }
+ if (prefix.endsWith(SLASH)) {
+ return prefix + sysId;
+ } else {
+ return prefix + SLASH + sysId;
}
}
}
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Tue Jan 12 15:29:21 2016 -0800
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Wed Jan 13 10:12:39 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,14 +27,13 @@
import javax.xml.catalog.CatalogFeatures.Feature;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
+import javax.xml.catalog.CatalogUriResolver;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import static jaxp.library.JAXPTestUtilities.getPathByClassName;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
@@ -42,12 +41,46 @@
import org.xml.sax.ext.DefaultHandler2;
/*
- * @bug 8081248, 8144966
+ * @bug 8081248, 8144966, 8146606
* @summary Tests basic Catalog functions.
*/
public class CatalogTest {
/*
+ @bug 8146606
+ Verifies that the resulting systemId does not contain duplicate slashes
+ */
+ public void testRewriteSystem() {
+ String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
+
+ try {
+ CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
+ String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId();
+ Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+
+ }
+
+ /*
+ @bug 8146606
+ Verifies that the resulting systemId does not contain duplicate slashes
+ */
+ public void testRewriteUri() {
+ String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
+
+ try {
+
+ CatalogUriResolver resolver = CatalogManager.catalogUriResolver(CatalogFeatures.defaults(), catalog);
+ String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId();
+ Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ /*
@bug 8144966
Verifies that passing null as CatalogFeatures will result in a NPE.
*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/rewriteCatalog.xml Wed Jan 13 10:12:39 2016 -0800
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<catalog
+ xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+
+ <rewriteSystem systemIdStartString="http://remote.com/dtd"
+ rewritePrefix="file:///share/docbook/docbook/pass"/>
+
+ <rewriteURI uriStartString="http://remote.com/import" rewritePrefix="file:///local/import" />
+
+</catalog>
+