From ff10d91cb881c3c0d5529491cf160044496b5e87 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Thu, 03 Feb 2011 11:49:44 +0000
Subject: [PATCH] Fix OPENDJ-27 : schema parsing fails with extensions on syntaxes.

---
 opends/src/server/org/opends/server/schema/MatchingRuleUseSyntax.java |   67 +++++++++++++++++++++++++--------
 1 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/opends/src/server/org/opends/server/schema/MatchingRuleUseSyntax.java b/opends/src/server/org/opends/server/schema/MatchingRuleUseSyntax.java
index 950f682..d3fb5c0 100644
--- a/opends/src/server/org/opends/server/schema/MatchingRuleUseSyntax.java
+++ b/opends/src/server/org/opends/server/schema/MatchingRuleUseSyntax.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Portions Copyright 2011 ForgeRock AS
  */
 package org.opends.server.schema;
 import org.opends.messages.Message;
@@ -1026,20 +1027,21 @@
    *                              the value.
    */
   private static int readExtraParameterValues(String valueStr,
-                          List<String> valueList, int startPos)
+                        List<String> valueList, int startPos)
           throws DirectoryException
   {
     // Skip over any leading spaces.
     int length = valueStr.length();
-    char c = valueStr.charAt(startPos++);
-    while ((startPos < length) && (c == ' '))
+    char c = '\u0000';
+    while ((startPos < length) && ((c = valueStr.charAt(startPos)) == ' '))
     {
-      c = valueStr.charAt(startPos++);
+      startPos++;
     }
 
     if (startPos >= length)
     {
-      Message message = ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
+      Message message =
+          ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
       throw new DirectoryException(
               ResultCode.INVALID_ATTRIBUTE_SYNTAX, message);
     }
@@ -1053,16 +1055,19 @@
     {
       // Parse until the closing quote.
       StringBuilder valueBuffer = new StringBuilder();
-      while ((startPos < length) && ((c = valueStr.charAt(startPos++)) != '\''))
+      startPos++;
+      while ((startPos < length) && ((c = valueStr.charAt(startPos)) != '\''))
       {
         valueBuffer.append(c);
+        startPos++;
       }
-
+      startPos++;
       valueList.add(valueBuffer.toString());
     }
     else if (c == '(')
     {
       startPos++;
+      // We're expecting a list of values. Quoted, space separated.
       while (true)
       {
         // Skip over any leading spaces;
@@ -1073,12 +1078,12 @@
 
         if (startPos >= length)
         {
-          Message message = ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
+          Message message =
+              ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
           throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                        message);
         }
 
-
         if (c == ')')
         {
           // This is the end of the list.
@@ -1094,10 +1099,41 @@
           throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                        message);
         }
+        else if (c == '\'')
+        {
+          // We have a quoted string
+          StringBuilder valueBuffer = new StringBuilder();
+          startPos++;
+          while ((startPos < length) &&
+              ((c = valueStr.charAt(startPos)) != '\''))
+          {
+            valueBuffer.append(c);
+            startPos++;
+          }
+
+          valueList.add(valueBuffer.toString());
+          startPos++;
+        }
         else
         {
-          // We'll recursively call this method to deal with this.
-          startPos = readExtraParameterValues(valueStr, valueList, startPos);
+          //Consider unquoted string
+          StringBuilder valueBuffer = new StringBuilder();
+          while ((startPos < length) &&
+              ((c = valueStr.charAt(startPos)) != ' '))
+          {
+            valueBuffer.append(c);
+            startPos++;
+          }
+
+          valueList.add(valueBuffer.toString());
+        }
+
+        if (startPos >= length)
+        {
+          Message message =
+              ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
+          throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
+                                       message);
         }
       }
     }
@@ -1105,16 +1141,15 @@
     {
       // Parse until the next space.
       StringBuilder valueBuffer = new StringBuilder();
-      while ((startPos < length) && ((c = valueStr.charAt(startPos++)) != ' '))
+      while ((startPos < length) && ((c = valueStr.charAt(startPos)) != ' '))
       {
         valueBuffer.append(c);
+        startPos++;
       }
 
       valueList.add(valueBuffer.toString());
     }
 
-
-
     // Skip over any trailing spaces.
     while ((startPos < length) && (valueStr.charAt(startPos) == ' '))
     {
@@ -1123,12 +1158,12 @@
 
     if (startPos >= length)
     {
-      Message message = ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
+      Message message =
+          ERR_ATTR_SYNTAX_MRUSE_TRUNCATED_VALUE.get(valueStr);
       throw new DirectoryException(
               ResultCode.INVALID_ATTRIBUTE_SYNTAX, message);
     }
 
-
     return startPos;
   }
 

--
Gitblit v1.10.0