mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
Reviewed-by: lancea
This commit is contained in:
parent
fdb8990307
commit
0224290c87
4 changed files with 72 additions and 15 deletions
|
@ -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 @@ final class RewriteSystem extends BaseEntry {
|
|||
public String getSystemIdStartString () {
|
||||
return systemIdStartString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rewritePrefix attribute.
|
||||
* @return The rewritePrefix attribute value.
|
||||
|
@ -80,7 +81,6 @@ final class RewriteSystem extends BaseEntry {
|
|||
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 @@ final class RewriteSystem extends BaseEntry {
|
|||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 @@ final class RewriteUri extends BaseEntry {
|
|||
public String getURIStartString () {
|
||||
return uriStartString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rewritePrefix attribute.
|
||||
* @return The rewritePrefix attribute value.
|
||||
|
@ -91,14 +92,20 @@ final class RewriteUri extends BaseEntry {
|
|||
*/
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
|||
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,11 +41,45 @@ import org.xml.sax.XMLReader;
|
|||
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.
|
||||
|
|
11
jaxp/test/javax/xml/jaxp/unittest/catalog/rewriteCatalog.xml
Normal file
11
jaxp/test/javax/xml/jaxp/unittest/catalog/rewriteCatalog.xml
Normal file
|
@ -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>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue