From 79987f6aa07a0beaae43f0fb08e20fe21be23016 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Mon, 13 Aug 2012 13:27:50 +0000
Subject: [PATCH] Fix OPENDJ-562 Country String syntax should validate ISO 3166 codes
---
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java
index f735c65..3ced4ae 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java
@@ -22,13 +22,13 @@
*
*
* Copyright 2009 Sun Microsystems, Inc.
+ * Portions Copyright 2012 Manuel Gaupp
*/
package org.forgerock.opendj.ldap.schema;
-import static com.forgerock.opendj.util.StaticUtils.toLowerCase;
import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH;
-import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE;
+import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_COUNTRY_STRING_NO_VALID_ISO_CODE;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
import org.forgerock.i18n.LocalizableMessageBuilder;
@@ -37,7 +37,7 @@
/**
* This class defines the country string attribute syntax, which should be a
* two-character ISO 3166 country code. However, for maintainability, it will
- * accept any value consisting entirely of two printable characters. In most
+ * accept any value consisting entirely of two upper-case characters. In most
* ways, it will behave like the directory string attribute syntax.
*/
final class CountryStringSyntaxImpl extends AbstractSyntaxImpl {
@@ -86,15 +86,16 @@
*/
public boolean valueIsAcceptable(final Schema schema, final ByteSequence value,
final LocalizableMessageBuilder invalidReason) {
- final String stringValue = toLowerCase(value.toString());
+ final String stringValue = value.toString();
if (stringValue.length() != 2) {
invalidReason.append(ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH.get(stringValue));
return false;
}
- if (!PrintableStringSyntaxImpl.isPrintableCharacter(stringValue.charAt(0))
- || !PrintableStringSyntaxImpl.isPrintableCharacter(stringValue.charAt(1))) {
- invalidReason.append(ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE.get(stringValue));
+ // Check for a string containing [A-Z][A-Z]
+ if (stringValue.charAt(0) < 'A' || stringValue.charAt(0) > 'Z'
+ || stringValue.charAt(1) < 'A' || stringValue.charAt(1) > 'Z') {
+ invalidReason.append(ERR_ATTR_SYNTAX_COUNTRY_STRING_NO_VALID_ISO_CODE.get(stringValue));
return false;
}
--
Gitblit v1.10.0