blob: 7e71ca161fbebf8d0f682e0b313b8eba4c83886e [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4802209
27 * @summary check that the right utf-8 encoder is used
28 */
29
30import java.io.*;
31import java.net.*;
32
33public class Encode implements Runnable {
34 public static void main(String args[]) throws Exception {
35 new Encode();
36 }
37
38 Encode() throws Exception {
39 ss = new ServerSocket(0);
40 (new Thread(this)).start();
41 String toEncode = "\uD800\uDC00 \uD801\uDC01 ";
42 String enc1 = URLEncoder.encode(toEncode, "UTF-8");
43 byte bytes[] = {};
44 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
45 InputStreamReader reader = new InputStreamReader( bais, "8859_1");
46 String url = "http://localhost:" + Integer.toString(ss.getLocalPort()) +
47 "/missing.nothtml";
48 HttpURLConnection uc = (HttpURLConnection)new URL(url).openConnection();
49 uc.connect();
50 String enc2 = URLEncoder.encode(toEncode, "UTF-8");
51 if (!enc1.equals(enc2))
52 throw new RuntimeException("test failed");
53 uc.disconnect();
54 }
55
56 ServerSocket ss;
57
58 public void run() {
59 try {
60 Socket s = ss.accept();
61 BufferedReader in = new BufferedReader(
62 new InputStreamReader(s.getInputStream()));
63 String req = in.readLine();
64 PrintStream out = new PrintStream(new BufferedOutputStream(
65 s.getOutputStream()));
66 out.print("HTTP/1.1 403 Forbidden\r\n");
67 out.print("\r\n");
68 out.flush();
69 s.close();
70 ss.close();
71 } catch (Exception e) {
72 e.printStackTrace();
73 }
74 }
75}