From dd48b2490617fb989ef27da3a29846b387128bc8 Mon Sep 17 00:00:00 2001 From: aefimov Date: Sun, 5 Jan 2014 21:02:57 -0800 Subject: [PATCH] 8027359: XML parser returns incorrect parsing results Reviewed-by: lancea --- .../8027359/XML11EntityScannerTest.java | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 test/javax/xml/jaxp/parsers/8027359/XML11EntityScannerTest.java diff --git a/test/javax/xml/jaxp/parsers/8027359/XML11EntityScannerTest.java b/test/javax/xml/jaxp/parsers/8027359/XML11EntityScannerTest.java new file mode 100644 index 000000000..a430b5f51 --- /dev/null +++ b/test/javax/xml/jaxp/parsers/8027359/XML11EntityScannerTest.java @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2013, 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 8027359 + * @summary test that the XML11EntityScanner refreshes cache when it loads new data + * @run main XML11EntityScannerTest + */ + +import java.io.*; +import java.util.regex.Pattern; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.*; + + +/** + * XML11EntityScanner functions similarly as XMLEntityScanner in handling data + * cache + */ +public class XML11EntityScannerTest { + static final String rawXML = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + /** + * main method. + * + * @param args Standard args. + */ + public static void main(String[] args) { + try { + final Document xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(rawXML.getBytes("UTF-8"))); + final Element identityElement = (Element) xmlDoc.getElementsByTagName("Identity").item(0); + final Element trustListElement = (Element) identityElement.getElementsByTagName("TrustList").item(0); + final NodeList trustList = trustListElement.getElementsByTagName("Trust"); + final Pattern keyPattern = Pattern.compile("USK@[%,~" + "*-_./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" + "]+"); + for (int i = 0; i < trustList.getLength(); ++i) { + Element trustElement = (Element) trustList.item(i); + final String identity = trustElement.getAttribute("Identity"); + if (!keyPattern.matcher(identity).matches()) { + throw new RuntimeException("Parsing failure: Instead of USK URI I got: " + identity); + } + } + } catch (Exception ex) { + throw new RuntimeException(ex.getMessage()); + } + } + +} -- GitLab