OPENDJ-3032 Fix throwIfIA5IllegalCharacter to check the whole string
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2015 ForgeRock AS. |
| | | * Portions copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | } |
| | | |
| | | private static void throwIfIA5IllegalCharacter(StringBuilder buffer, ByteSequence value) throws DecodeException { |
| | | // Replace any consecutive spaces with a single space and watch out |
| | | // for non-ASCII characters. |
| | | for (int pos = buffer.length() - 1; pos > 0; pos--) { |
| | | // Check the string for any non-IA5 characters |
| | | final int bufferLength = buffer.length(); |
| | | for (int pos = 0; pos < bufferLength; pos++) { |
| | | final char c = buffer.charAt(pos); |
| | | if ((c & 0x7F) != c) { |
| | | // This is not a valid character for an IA5 string. If strict |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2015 ForgeRock AS. |
| | | * Portions copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | @DataProvider |
| | | public Object[][] nonAsciiStringProvider() throws Exception { |
| | | final String nonAsciiChars = "ëéèêœ"; |
| | | final String singleNonAsciiChar = "ë"; |
| | | final String nonAsciiCharsReplacement = new String( |
| | | new byte[] { b(0x65), b(0xcc), b(0x88), b(0x65), b(0xcc), |
| | | b(0x81), b(0x65), b(0xcc), b(0x80), b(0x65), b(0xcc), |
| | | b(0x82), b(0xc5), b(0x93), }, "UTF8"); |
| | | final String singleNonAsciiCharReplacement = new String( |
| | | new byte[] { b(0x65), b(0xcc), b(0x88) }, "UTF8"); |
| | | return new Object[][] { |
| | | { nonAsciiChars, false, false, nonAsciiCharsReplacement }, |
| | | { nonAsciiChars, false, true, nonAsciiCharsReplacement }, |
| | | { nonAsciiChars, true, false, nonAsciiCharsReplacement }, |
| | | { nonAsciiChars, true, true, nonAsciiCharsReplacement }, |
| | | { singleNonAsciiChar, true, true, singleNonAsciiCharReplacement } |
| | | }; |
| | | } |
| | | |