test/jdk/java/net/IDN/UseSTD3ASCIIRules.java
author aeubanks
Tue, 16 Apr 2019 13:06:23 -0700
changeset 54770 62b6e7587b1f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8220673: Add test library support for determining platform IP support Reviewed-by: dfuchs, chegar Contributed-by: aeubanks@google.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19790
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     1
/*
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     4
 *
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     8
 *
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    13
 * accompanied this code).
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    14
 *
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    18
 *
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    21
 * questions.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    22
 */
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    23
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    24
/*
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    25
 * @test
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    26
 * @bug 8023881
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    27
 * @summary IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    28
 *          in IDN.toASCII
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    29
 */
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    30
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    31
import java.net.*;
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    32
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    33
public class UseSTD3ASCIIRules {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    34
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    36
        // Per Section 4.1, RFC 3490, if the UseSTD3ASCIIRules flag is set,
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    37
        // then perform these checks:
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    38
        //
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    39
        // (a) Verify the absence of non-LDH ASCII code points; that is, the
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    40
        //     absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    41
        //
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    42
        // (b) Verify the absence of leading and trailing hyphen-minus; that
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    43
        //     is, the absence of U+002D at the beginning and end of the
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    44
        //     sequence.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    45
        String[] illegalNames = {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    46
                "www.example.com-",
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    47
                "-www.example.com",
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    48
                "-www.example.com-",
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    49
                "www.ex\u002Cmple.com",
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    50
                "www.ex\u007Bmple.com",
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    51
                "www.ex\u007Fmple.com"
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    52
            };
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    53
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    54
        String[] legalNames = {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    55
                "www.ex-ample.com",
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    56
                "www.ex\u002Dmple.com",         // www.ex-mple.com
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    57
                "www.ex\u007Ample.com",         // www.exzmple.com
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    58
                "www.ex\u3042mple.com",         // www.xn--exmple-j43e.com
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    59
                "www.\u3042\u3044\u3046.com",   // www.xn--l8jeg.com
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    60
                "www.\u793A\u4F8B.com"          // www.xn--fsq092h.com
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    61
            };
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    62
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    63
        for (String name : illegalNames) {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    64
            try {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    65
                System.out.println("Convering illegal IDN: " + name);
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    66
                IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES);
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    67
                throw new Exception(
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    68
                    "Expected to get IllegalArgumentException for " + name);
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    69
            } catch (IllegalArgumentException iae) {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    70
                // That's the right behavior.
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    71
            }
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    72
        }
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    73
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    74
        for (String name : legalNames) {
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    75
            System.out.println("Convering legal IDN: " + name);
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    76
            System.out.println("\tThe ACE form is: " +
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    77
                        IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES));
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    78
        }
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    79
    }
d97d46e9bddf 8023881: IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode in IDN.toASCII
xuelei
parents:
diff changeset
    80
}