Index: src/test/org/apache/ldap/common/name/DnParserTest.java =================================================================== --- src/test/org/apache/ldap/common/name/DnParserTest.java (revision 359133) +++ src/test/org/apache/ldap/common/name/DnParserTest.java (working copy) @@ -240,6 +240,31 @@ * * @throws NamingException if anything goes wrong */ + public final void testParseStringRFC2253_7() throws NamingException + { + DnParser parser = new DnParser(); + + // a space character occurring at the end of the string + Name nameRFC2253_7 = parser.parse( "CN=foo\\ ,O=bar" ); + + assertEquals( "RFC2253_7 : ", + "CN=foo\\ ,O=bar", + nameRFC2253_7.toString() ); + + // a space character occurring at the begining of the string + nameRFC2253_7 = parser.parse( "CN=\\ foo ,O=bar" ); + + assertEquals( "RFC2253_7 : ", + "CN=\\ foo,O=bar", + nameRFC2253_7.toString() ); + } + + + /** + * Class under test for Name parse(String) + * + * @throws NamingException if anything goes wrong + */ public final void testParseInvalidString() throws NamingException { DnParser parser = new DnParser(); Index: src/antlr/valuelexer.g =================================================================== --- src/antlr/valuelexer.g (revision 329878) +++ src/antlr/valuelexer.g (working copy) @@ -114,6 +114,7 @@ ( ( ',' | '=' | '+' | '<' | '>' | '#' | ';' ) | '\\' | '"' + | ' ' | HEXPAIR ) ; @@ -125,10 +126,12 @@ '"' ; -SIMPLE_STRING : ( ~( ',' | '=' | '+' | '<' | +SIMPLE_STRING : ( ~( ',' | '=' | '+' | '<' | ' ' | '>' | '#' | ';' | '\\' | '"' ) )* ; +SPACE : ( ' ' )+ + ; //////////////////////////////////////////// Index: src/antlr/valueparser.g =================================================================== --- src/antlr/valueparser.g (revision 329878) +++ src/antlr/valueparser.g (working copy) @@ -59,9 +59,10 @@ value returns [ String l_val ] { l_val = null ; + int lastNonSpace = -1 ; StringBuffer l_buf = new StringBuffer() ; } - : ( tok0:SIMPLE_STRING + : (( tok0:SIMPLE_STRING { // // This is where the normalizer comes into play where @@ -120,10 +121,28 @@ { l_buf.append( tok3.getText() ) ; } + }) + { + // Record last non space. + lastNonSpace = l_buf.length(); } + | tok4:SPACE + { + // Skip space if no other chars have been parsed yet. + if (lastNonSpace > 0) + { + l_buf.append(tok4.getText()); + } + } )+ { - l_val = l_buf.toString().trim() ; + // Trim off trailing spaces. + if (lastNonSpace < l_buf.length()) + { + l_buf.delete(lastNonSpace, l_buf.length()); + } + + l_val = l_buf.toString(); } ; exception