Path: blob/master/test/jdk/javax/naming/ldap/LdapName/TrailingSpaceTest.java
41153 views
/*1* Copyright (c) 2004, 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 498533926* @summary javax.naming.ldap.LdapName(String) doesn't parse27* some strings well28*/2930import javax.naming.ldap.*;31import javax.naming.*;3233public class TrailingSpaceTest {3435public static void main(String[] args) throws Exception {36String[] input = {"cn=Tyler\\ ",37"cn=Ty ler",38"cn=Tyler\\\\ ",39"cn=Tyler\\\\\\ ",40"cn= Tyler ",41"cn=Tyler\\\\ \\ ",42"cn= ",43"cn= \\ "44};4546String[] expected = { "Tyler ",47"Ty ler",48"Tyler\\",49"Tyler\\ ",50"Tyler",51"Tyler\\ ",52"",53" "54};5556try {57System.out.println("*************************");58System.out.println();5960for (int i = 0; i < input.length; i++) {6162Rdn rdn = new Rdn(input[i]);6364System.out.println((i + 1) + ") RDN string: [" +65input[i] + "]");66Object value = rdn.getValue();6768// escape the value69String escaped = Rdn.escapeValue(value);70System.out.println("escaped: [" + escaped + "]");7172// unescape the value73String unescaped = (String) Rdn.unescapeValue(escaped);74System.out.println("unescaped: [" + unescaped + "]");7576System.out.println();77System.out.println("*************************");78System.out.println();7980if (!unescaped.equals(expected[i])) {81throw new Exception("Invalid unescaping for: " +82" input #" + (i + 1));83}84}85} catch (InvalidNameException e) {86e.printStackTrace();87}88}89}909192