Path: blob/master/test/jdk/java/net/URLEncoder/Decoder.java
41149 views
/*1* Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 440761026* @summary java.net.URLDecode.decode(st,"UTF-16") works incorrectly on '+' sign27*/2829import java.net.*;3031public class Decoder {3233public static void main(String args[]) throws Exception {3435boolean passed = true;36String enc = "UTF-16";37String strings[] = {38"\u0100\u0101",39"\u0100 \u0101",40"\u0100 \u0101\u0102",41"\u0100 \u0101 \u0102",42"\u0100C\u0101 \u0102",43"\u0100\u0101\u0102",44"?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&",45"foobar",46"foo?bar"47};4849for (int i = 0; i < strings.length; i++) {50String encoded = URLEncoder.encode(strings[i], enc);51System.out.println("ecnoded: " + encoded);52String decoded = URLDecoder.decode(encoded, enc);53System.out.print("init: ");54printString(strings[i]);55System.out.print("decoded: ");56printString(decoded);57if (strings[i].equals(decoded)) {58System.out.println(" - correct - \n");59} else {60System.out.println(" - incorrect - \n");61throw new RuntimeException ("Unexpected decoded output on string " + i);62}63}64}6566static void printString(String s) {67for (int i = 0; i < s.length(); i++) {68System.out.print((int)s.charAt(i) + " ");69}70System.out.println();71}72}737475