From 61be60eef8694b2c28386faf6dd2d7c4e842addd Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 16 Jun 2011 18:00:52 +0000
Subject: [PATCH] Fix OPENDJ-198: RFC 4512 compliance for ldap-toolkit
---
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java | 51 ++++++++++++++++++++++++++++++---------------------
1 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java
index 4c398c3..8f8c6b7 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2009 Sun Microsystems, Inc.
+ * Portions copyright 2011 ForgeRock AS
*/
package org.forgerock.opendj.ldap.schema;
@@ -30,6 +31,7 @@
import static com.forgerock.opendj.util.StaticUtils.isAlpha;
import static com.forgerock.opendj.util.StaticUtils.isDigit;
+import static com.forgerock.opendj.util.StaticUtils.isKeyChar;
import static org.forgerock.opendj.ldap.CoreMessages.*;
import java.util.*;
@@ -137,10 +139,10 @@
- static List<String> readNameDescriptors(final SubstringReader reader)
+ static List<String> readNameDescriptors(
+ final SubstringReader reader, final boolean allowCompatChars)
throws DecodeException
{
- int length = 0;
List<String> values;
// Skip over any spaces at the beginning of the value.
@@ -148,18 +150,13 @@
try
{
+ reader.mark();
char c = reader.read();
if (c == '\'')
{
- reader.mark();
- // Parse until the closing quote.
- while (reader.read() != '\'')
- {
- length++;
- }
-
reader.reset();
- values = Collections.singletonList(reader.read(length));
+ values = Collections.singletonList(readQuotedDescriptor(
+ reader, allowCompatChars));
reader.read();
}
else if (c == '(')
@@ -179,7 +176,7 @@
do
{
reader.reset();
- values.add(readQuotedDescriptor(reader));
+ values.add(readQuotedDescriptor(reader, allowCompatChars));
reader.skipWhitespaces();
reader.mark();
}
@@ -211,11 +208,15 @@
*
* @param reader
* The string representation of the definition.
+ * @param allowCompatChars
+ * {@code true} if certain illegal characters should be allowed for
+ * compatibility reasons.
* @return The attribute description or numeric OID read from the definition.
* @throws DecodeException
* If a problem is encountered while reading the name or OID.
*/
- static String readOID(final SubstringReader reader) throws DecodeException
+ static String readOID(final SubstringReader reader,
+ final boolean allowCompatChars) throws DecodeException
{
int length = 0;
boolean enclosingQuote = false;
@@ -305,7 +306,7 @@
throw DecodeException.error(message);
}
- if (!isAlpha(c) && !isDigit(c) && c != '-' && c != '.' && c != '_')
+ if (!isKeyChar(c, allowCompatChars))
{
// This is an illegal character.
final LocalizableMessage message = ERR_ATTR_SYNTAX_ILLEGAL_CHAR_IN_STRING_OID
@@ -355,11 +356,15 @@
*
* @param reader
* The string representation of the definition.
+ * @param allowCompatChars
+ * {@code true} if certain illegal characters should be allowed for
+ * compatibility reasons.
* @return The OID read from the definition.
* @throws DecodeException
* If a problem is encountered while reading the token name.
*/
- static String readOIDLen(final SubstringReader reader) throws DecodeException
+ static String readOIDLen(final SubstringReader reader,
+ final boolean allowCompatChars) throws DecodeException
{
int length = 1;
boolean enclosingQuote = false;
@@ -445,7 +450,7 @@
throw DecodeException.error(message);
}
- if (!isAlpha(c) && !isDigit(c) && c != '-' && c != '.' && c != '_')
+ if (!isKeyChar(c, allowCompatChars))
{
// This is an illegal character.
final LocalizableMessage message = ERR_ATTR_SYNTAX_ILLEGAL_CHAR_IN_STRING_OID
@@ -505,8 +510,8 @@
- static Set<String> readOIDs(final SubstringReader reader)
- throws DecodeException
+ static Set<String> readOIDs(final SubstringReader reader,
+ final boolean allowCompatChars) throws DecodeException
{
Set<String> values;
@@ -522,7 +527,7 @@
values = new LinkedHashSet<String>();
do
{
- values.add(readOID(reader));
+ values.add(readOID(reader, allowCompatChars));
// Skip over any trailing spaces;
reader.skipWhitespaces();
@@ -533,7 +538,7 @@
else
{
reader.reset();
- values = Collections.singleton(readOID(reader));
+ values = Collections.singleton(readOID(reader, allowCompatChars));
}
return values;
@@ -828,11 +833,15 @@
*
* @param reader
* The string representation of the definition.
+ * @param allowCompatChars
+ * {@code true} if certain illegal characters should be allowed for
+ * compatibility reasons.
* @return The string value read from the definition.
* @throws DecodeException
* If a problem is encountered while reading the quoted string.
*/
- private static String readQuotedDescriptor(final SubstringReader reader)
+ private static String readQuotedDescriptor(
+ final SubstringReader reader, final boolean allowCompatChars)
throws DecodeException
{
int length = 0;
@@ -863,7 +872,7 @@
throw DecodeException.error(message);
}
- if (!isAlpha(c) && !isDigit(c) && c != '-' && c != '_' && c != '.')
+ if (!isKeyChar(c, allowCompatChars))
{
// This is an illegal character.
final LocalizableMessage message = ERR_ATTR_SYNTAX_ILLEGAL_CHAR_IN_STRING_OID
--
Gitblit v1.10.0