1 /* 2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package parsers; 25 26 import java.io.File; 27 import java.io.FileWriter; 28 import java.io.PrintWriter; 29 30 import javax.xml.parsers.SAXParserFactory; 31 32 import org.testng.Assert; 33 import org.testng.annotations.Listeners; 34 import org.testng.annotations.Test; 35 import org.xml.sax.Attributes; 36 import org.xml.sax.SAXException; 37 import org.xml.sax.helpers.DefaultHandler; 38 39 /* 40 * @bug 6341770 41 * @summary Test external entity linked to non-ASCII base URL. 42 */ 43 @Listeners({jaxp.library.FilePolicy.class}) 44 public class Bug6341770 { 45 46 // naming a file "aux" would fail on windows. 47 @Test 48 public void testNonAsciiURI() { 49 try { 50 File dir = new File("sko\u0159ice"); 51 dir.delete(); 52 dir.mkdir(); 53 File main = new File(dir, "main.xml"); 54 PrintWriter w = new PrintWriter(new FileWriter(main)); 55 w.println("<!DOCTYPE r [<!ENTITY aux SYSTEM \"aux1.xml\">]>"); 56 w.println("<r>&aux;</r>"); 57 w.flush(); 58 w.close(); 59 File aux = new File(dir, "aux1.xml"); 60 w = new PrintWriter(new FileWriter(aux)); 61 w.println("<x/>"); 62 w.flush(); 63 w.close(); 64 System.out.println("Parsing: " + main); 65 SAXParserFactory.newInstance().newSAXParser().parse(main, new DefaultHandler() { 66 public void startElement(String uri, String localname, String qname, Attributes attr) throws SAXException { 67 System.out.println("encountered <" + qname + ">"); 68 } 69 }); 70 } catch (Exception e) { 71 e.printStackTrace(); 72 Assert.fail("Exception: " + e.getMessage()); 73 } 74 System.out.println("OK."); 75 } 76 }