Mercurial > hg > openjdk > jdk8u > jdk
changeset 12811:3742cb9c55fd jdk8u161-b03
8159240: XSOM parser incorrectly processes type names with whitespaces
Reviewed-by: coffeys
author | aefimov |
---|---|
date | Mon, 02 Oct 2017 14:20:37 +0100 |
parents | 90f10a2d0b6f |
children | d9852749777c |
files | test/javax/xml/bind/xsom/8159240/WhitespacesTest.java test/javax/xml/bind/xsom/8159240/complexType.xsd test/javax/xml/bind/xsom/8159240/complexTypeExtension.xsd test/javax/xml/bind/xsom/8159240/complexTypeRestriction.xsd test/javax/xml/bind/xsom/8159240/identityConstraint.xsd test/javax/xml/bind/xsom/8159240/particlesAndAttributes.xsd test/javax/xml/bind/xsom/8159240/simpleType.xsd |
diffstat | 7 files changed, 341 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/WhitespacesTest.java Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8159240 + * @summary Check if types and names with whitespaces are collapsed by + * XSOM schema parser + * @compile -XDignore.symbol.file WhitespacesTest.java + * @run testng WhitespacesTest + * + */ + +import com.sun.xml.internal.xsom.parser.XSOMParser; +import java.io.File; +import java.nio.file.Paths; +import javax.xml.parsers.SAXParserFactory; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +public class WhitespacesTest { + + @Test(dataProvider = "TestSchemaFiles") + public void testWhitespacesCollapse(String schemaFile) throws Exception { + XSOMParser parser = new XSOMParser(SAXParserFactory.newInstance()); + XsomErrorHandler eh = new XsomErrorHandler(); + + parser.setErrorHandler(eh); + parser.parse(getSchemaFile(schemaFile)); + + if (eh.gotError) { + throw new RuntimeException("XSOM parser encountered error", eh.e); + } + } + + // Get location of schema file located in test source directory + private static File getSchemaFile(String filename) { + String testSrc = System.getProperty("test.src", "."); + return Paths.get(testSrc).resolve(filename).toFile(); + } + + @DataProvider(name = "TestSchemaFiles") + private Object[][] dataTestSchemaFiles() { + return new Object[][] { + {"complexType.xsd"}, + {"complexTypeExtension.xsd"}, + {"complexTypeRestriction.xsd"}, + {"identityConstraint.xsd"}, + {"particlesAndAttributes.xsd"}, + {"simpleType.xsd"} + }; + + } + + // Test XSOM error handler + private static class XsomErrorHandler implements ErrorHandler { + + public boolean gotError = false; + public Exception e = null; + + @Override + public void warning(SAXParseException ex) throws SAXException { + System.err.println("XSOM warning:" + ex); + } + + @Override + public void error(SAXParseException ex) throws SAXException { + System.err.println("XSOM error:" + ex); + e = ex; + gotError = true; + } + + @Override + public void fatalError(SAXParseException ex) throws SAXException { + System.err.println("XSOM fatal error:" + ex); + e = ex; + gotError = true; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/complexType.xsd Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,23 @@ +<?xml version="1.0"?> + +<!-- Test for whitespaces in xs:complexType 'name' and xs:element 'type' attribute --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:hy="http://www.test.com/Service/" + targetNamespace="http://www.test.com/Service/"> + <xsd:element name="HelloRequest" type="xsd:string"/> + <xsd:element name="HelloResponse" type="xsd:string"/> + <xsd:complexType name=" info "> + <xsd:sequence> + <xsd:element name="firstname" type="xsd:string"/> + <xsd:element name="lastname" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + <xsd:complexType name="usage"> + <xsd:all> + <xsd:element name="customerCharacteristics" type=" + hy:info + "/> + </xsd:all> + </xsd:complexType> +</xsd:schema>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/complexTypeExtension.xsd Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,49 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <!-- Test for whitespaces in xs:complexType -> xs:extension 'base' attribute value --> + + <xs:simpleType name="size"> + <xs:restriction base="xs:string"> + <xs:enumeration value="small" /> + <xs:enumeration value="medium" /> + <xs:enumeration value="large" /> + </xs:restriction> + </xs:simpleType> + + <xs:complexType name="jeans"> + <xs:simpleContent> + <xs:extension base="size"> + <xs:attribute name="sex"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="male" /> + <xs:enumeration value="female" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:element name="employee" type=" fullpersoninfo "/> + + <xs:complexType name=" personinfo "> + <xs:sequence> + <xs:element name="firstname" type="xs:string"/> + <xs:element name="lastname" type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="fullpersoninfo "> + <xs:complexContent> + <xs:extension base=" personinfo"> + <xs:sequence> + <xs:element name="address" type="xs:string"/> + <xs:element name="city" type="xs:string"/> + <xs:element name="country" type="xs:string"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> +</xs:schema>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/complexTypeRestriction.xsd Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:hy="http://www.test.com/Service/" + targetNamespace="http://www.test.com/Service/"> + + <xs:simpleType name=" size "> + <xs:restriction base=" xs:string"> + <xs:enumeration value="small" /> + <xs:enumeration value="medium" /> + <xs:enumeration value="large" /> + </xs:restriction> + </xs:simpleType> + + <xs:complexType name="jeans"> + <xs:simpleContent> + <xs:restriction base=" hy:size"> + <xs:attribute name="sex"> + <xs:simpleType> + <xs:restriction base=" xs:string "> + <xs:enumeration value="male" /> + <xs:enumeration value="female" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:restriction> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="customer "> + <xs:sequence> + <xs:element name=" firstname" type="xs:string"/> + <xs:element name=" lastname " type="xs:string"/> + <xs:element name=" country " type="xs:string"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="Norwegian_customer"> + <xs:complexContent> + <xs:restriction base=" hy:customer "> + <xs:sequence> + <xs:element name=" firstname" type=" xs:string "/> + <xs:element name="lastname " type="xs:string "/> + <xs:element name="country" type="xs:string " fixed="Norway"/> + </xs:sequence> + </xs:restriction> + </xs:complexContent> + </xs:complexType> +</xs:schema>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/identityConstraint.xsd Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <!-- Test spaces in xs:key and xs:keyref 'name' + and 'refer' attributes --> + <xs:element name="root"> + <xs:complexType> + <xs:sequence> + <xs:element name="referenced"> + <xs:complexType> + <xs:attribute name="id" type="xs:string" /> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:key name="aKey "> + <xs:selector xpath="root" /> + <xs:field xpath="@id" /> + </xs:key> + <xs:keyref name=" aKeyRef " refer=" aKey"> + <xs:selector xpath="referenced" /> + <xs:field xpath="@id" /> + </xs:keyref> + </xs:element> +</xs:schema>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/particlesAndAttributes.xsd Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,63 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <!-- Test spaces in 'xs:element' 'substitutionGroup' attribute --> + <xs:element name=" name" type="xs:string"/> + <xs:element name="navn" substitutionGroup=" name "/> + + <!-- Test spaces in 'xs:element' 'name' and 'ref' attributes --> + <xs:element name=" address "> + <xs:complexType> + <xs:sequence> + <xs:element name="street" type="xs:string"/> + <xs:element name="building" type="xs:string"/> + <xs:element name="apt" type="xs:int"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="personinfo"> + <xs:complexType> + <xs:all> + <xs:element name="firstname" type="xs:string"/> + <xs:element ref="address123 "/> + <xs:element name="city" type="xs:string"/> + <xs:element name="country" type="xs:string"/> + </xs:all> + </xs:complexType> + </xs:element> + + <!-- Test spaces in xs:attribute 'name', 'type' and 'ref' attributes --> + <xs:simpleType name="typeForAttribute "> + <xs:restriction base=" xs:string"> + <xs:pattern value="[A-Z][A-Z]"/> + </xs:restriction> + </xs:simpleType> + <xs:attribute name=" code" type=" typeForAttribute"> + </xs:attribute> + <xs:complexType name="TestComplexType"> + <xs:attribute ref="code "/> + </xs:complexType> + + <!-- Test spaces in xs:attributeGroup 'name' and 'ref' attributes --> + <xs:attributeGroup name="personattr "> + <xs:attribute name="attr1" type="xs:string"/> + <xs:attribute name="attr2" type="xs:integer"/> + </xs:attributeGroup> + <xs:complexType name="person"> + <xs:attributeGroup ref=" personattr "/> + </xs:complexType> + + <!-- Test spaces in <xs:group> 'name' and 'ref' attributes --> + <xs:group name=" customer"> + <xs:sequence> + <xs:element name="firstname" type="xs:string"/> + <xs:element name="secondname" type="xs:string"/> + </xs:sequence> + </xs:group> + <xs:complexType name="orderType"> + <xs:group ref="customer "/> + <xs:attribute name="itemId" type="xs:integer"/> + </xs:complexType> + <xs:element name="order" type="orderType"/> + +</xs:schema>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/xsom/8159240/simpleType.xsd Mon Oct 02 14:20:37 2017 +0100 @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <!-- Test spaces in elementDeclBody 'type' attribute --> + <xs:element name="intvalues" type="valuelist "/> + + <!-- Test spaces in simpleType 'name' attribute + and in inner <xs:list> 'itemType' attribute --> + <xs:simpleType name=" valuelist "> + <xs:list itemType=" xs:integer "/> + </xs:simpleType> + + <!-- Test spaces in <xs:simpleType> -> <xs:restriction> 'base' + attribute --> + <xs:element name="stringWithRestriction" type=" tenSizedString"/> + <xs:simpleType name=" tenSizedString "> + <xs:restriction base=" xs:string "> + <xs:minLength value="10"/> + <xs:maxLength value="10"/> + </xs:restriction> + </xs:simpleType> + + <!-- Test spaces in <xs:simpleType> -> <xs:union> 'memberTypes' + attribute --> + <xs:element name="stringAndIntsUnion" type=" stringsAndInts "/> + <xs:simpleType name="stringsAndInts"> + <xs:union memberTypes=" xs:integer xs:string + tenSizedString " /> + </xs:simpleType> + +</xs:schema>