1 /* 2 * Copyright (c) 2014, 2015, 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.Test; 34 import org.xml.sax.Attributes; 35 import org.xml.sax.SAXException; 36 import org.xml.sax.helpers.DefaultHandler; 37 38 /* 39 * @bug 6341770 40 * @summary Test external entity linked to non-ASCII base URL. 41 */ 42 public class Bug6341770 { 43 44 // naming a file "aux" would fail on windows. 45 @Test 46 public void testNonAsciiURI() { 47 try { 48 File dir = File.createTempFile("sko\u0159ice", null); 49 dir.delete(); 50 dir.mkdir(); 51 File main = new File(dir, "main.xml"); 52 PrintWriter w = new PrintWriter(new FileWriter(main)); 53 w.println("<!DOCTYPE r [<!ENTITY aux SYSTEM \"aux1.xml\">]>"); 54 w.println("<r>&aux;</r>"); 55 w.flush(); 56 w.close(); 57 File aux = new File(dir, "aux1.xml"); 58 w = new PrintWriter(new FileWriter(aux)); 59 w.println("<x/>"); 60 w.flush(); 61 w.close(); 62 System.out.println("Parsing: " + main); 63 SAXParserFactory.newInstance().newSAXParser().parse(main, new DefaultHandler() { 64 public void startElement(String uri, String localname, String qname, Attributes attr) throws SAXException { 65 System.out.println("encountered <" + qname + ">"); 66 } 67 }); 68 } catch (Exception e) { 69 e.printStackTrace(); 70 Assert.fail("Exception: " + e.getMessage()); 71 } 72 System.out.println("OK."); 73 } 74 }