You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2014/06/14 01:09:51 UTC
svn commit: r1602537 - in /directory/shared/trunk/ldap/schema/converter/src:
main/antlr/ test/java/org/apache/directory/api/converter/schema/
test/resources/org/apache/directory/api/converter/schema/
Author: elecharny
Date: Fri Jun 13 23:09:50 2014
New Revision: 1602537
URL: http://svn.apache.org/r1602537
Log:
A fix for DIRAPI-67 : we now support escaped chars in a schema description
Added:
directory/shared/trunk/ldap/schema/converter/src/test/resources/org/apache/directory/api/converter/schema/testATDescWithEscaped.schema
Modified:
directory/shared/trunk/ldap/schema/converter/src/main/antlr/schemaConverter.g
directory/shared/trunk/ldap/schema/converter/src/test/java/org/apache/directory/api/converter/schema/TestSchemaToLdif.java
Modified: directory/shared/trunk/ldap/schema/converter/src/main/antlr/schemaConverter.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/converter/src/main/antlr/schemaConverter.g?rev=1602537&r1=1602536&r2=1602537&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/converter/src/main/antlr/schemaConverter.g (original)
+++ directory/shared/trunk/ldap/schema/converter/src/main/antlr/schemaConverter.g Fri Jun 13 23:09:50 2014
@@ -101,7 +101,7 @@ IDENTIFIER options { testLiterals=true;
DESC
:
- "desc" WS QUOTE ( ~'\'' )+ QUOTE
+ "desc" WS QUOTE ( ~'\'' | '\\' '\'' )+ QUOTE
;
SYNTAX
@@ -252,30 +252,14 @@ woidlist returns [List<String> list]
objectClassDesc [ObjectClassHolder objectClass]
: d:DESC
{
- String desc = d.getText().split( "'" )[1];
- String[] quoted = desc.split( "\"" );
-
- if ( quoted.length == 1 )
- {
- objectClass.setDescription( desc );
- }
- else
- {
- StringBuffer buf = new StringBuffer();
- for ( int ii = 0; ii < quoted.length; ii++ )
- {
- if ( ii < quoted.length - 1 )
- {
- buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
- }
- else
- {
- buf.append( quoted[ii] );
- }
- }
-
- objectClass.setDescription( buf.toString() );
- }
+ String text = d.getText();
+ int start = text.indexOf( '\'' );
+ String desc = text.substring( start + 1, text.length() - 1 );
+ desc = desc.replace( "\\\"", "\"" );
+ desc = desc.replace( "\\'", "'" );
+ desc = desc.replace( "\\27", "'" );
+ desc = desc.replace( "\\5C", "\"" );
+ objectClass.setDescription( desc );
}
;
@@ -324,7 +308,7 @@ attributeType
type = new AttributeTypeHolder( oid.getText() );
}
( names[type] )?
- ( desc[type] )?
+ ( attributeTypeDesc[type] )?
( "OBSOLETE" { type.setObsolete( true ); } )?
( superior[type] )?
( equality[type] )?
@@ -344,33 +328,17 @@ attributeType
;
-desc [AttributeTypeHolder type]
+attributeTypeDesc [AttributeTypeHolder type]
: d:DESC
{
- String desc = d.getText().split( "'" )[1];
- String[] quoted = desc.split( "\"" );
-
- if ( quoted.length == 1 )
- {
- type.setDescription( desc );
- }
- else
- {
- StringBuffer buf = new StringBuffer();
- for ( int ii = 0; ii < quoted.length; ii++ )
- {
- if ( ii < quoted.length - 1 )
- {
- buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
- }
- else
- {
- buf.append( quoted[ii] );
- }
- }
-
- type.setDescription( buf.toString() );
- }
+ String text = d.getText();
+ int start = text.indexOf( '\'' );
+ String desc = text.substring( start +1, text.length() - 1 );
+ desc = desc.replace( "\\\"", "\"" );
+ desc = desc.replace( "\\'", "'" );
+ desc = desc.replace( "\\27", "'" );
+ desc = desc.replace( "\\5C", "\"" );
+ type.setDescription( desc );
}
;
Modified: directory/shared/trunk/ldap/schema/converter/src/test/java/org/apache/directory/api/converter/schema/TestSchemaToLdif.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/converter/src/test/java/org/apache/directory/api/converter/schema/TestSchemaToLdif.java?rev=1602537&r1=1602536&r2=1602537&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/converter/src/test/java/org/apache/directory/api/converter/schema/TestSchemaToLdif.java (original)
+++ directory/shared/trunk/ldap/schema/converter/src/test/java/org/apache/directory/api/converter/schema/TestSchemaToLdif.java Fri Jun 13 23:09:50 2014
@@ -543,6 +543,23 @@ public class TestSchemaToLdif
@Test
+ public void testConvertATDesWithEscapedChars() throws ParserException, IOException
+ {
+ String expected =
+ HEADER +
+ "dn: m-oid=1.3.6.1.4.1.18060.0.4.2.3.14, ou=attributetypes, cn=testATDescWithEsca\n" +
+ " ped, ou=schema\n" +
+ "objectclass: metaAttributeType\n" +
+ "objectclass: metaTop\n" +
+ "objectclass: top\n" +
+ "m-oid: 1.3.6.1.4.1.18060.0.4.2.3.14\n" +
+ "m-description: Some 'escaped' chars\n\n";
+
+ assertEquals( expected, transform( "testATDescWithEscaped" ) );
+ }
+
+
+ @Test
public void testConvertATObsolete() throws ParserException, IOException
{
String expected =
Added: directory/shared/trunk/ldap/schema/converter/src/test/resources/org/apache/directory/api/converter/schema/testATDescWithEscaped.schema
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/converter/src/test/resources/org/apache/directory/api/converter/schema/testATDescWithEscaped.schema?rev=1602537&view=auto
==============================================================================
--- directory/shared/trunk/ldap/schema/converter/src/test/resources/org/apache/directory/api/converter/schema/testATDescWithEscaped.schema (added)
+++ directory/shared/trunk/ldap/schema/converter/src/test/resources/org/apache/directory/api/converter/schema/testATDescWithEscaped.schema Fri Jun 13 23:09:50 2014
@@ -0,0 +1,28 @@
+#############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#############################################################################
+# =============================================================================
+# ApacheDS schema for storing DNS zones in LDAP
+# =============================================================================
+# +---------------------------+-----------------+
+# | Apache OID | description |
+# +---------------------------+-----------------+
+# +---------------------------+-----------------+
+# =============================================================================
+attributetype ( 1.3.6.1.4.1.18060.0.4.2.3.14
+ DESC 'Some \27escaped\27 chars'
+ )
+
\ No newline at end of file