From 3adda24c610ffb45e3c60a7f0114a1945ccbd6e4 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 09 Oct 2015 11:49:40 +0000
Subject: [PATCH] OPENDJ-2325: align DN.toNormalizedUrlSafeString() with SDK

---
 opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java |   40 ++++++++++++++++++++--------------------
 opendj-server-legacy/src/main/java/org/opends/server/types/DN.java     |   10 +++-------
 2 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java b/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java
index 9d67b04..97543f8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java
@@ -2616,16 +2616,12 @@
     {
       return "";
     }
-
     StringBuilder buffer = new StringBuilder();
-    buffer.append(rdnComponents[0].toNormalizedUrlSafeString());
-
-    for (int i=1; i < rdnComponents.length; i++)
+    buffer.append(rdnComponents[numComponents - 1].toNormalizedUrlSafeString());
+    for (int i = numComponents - 2; i >= 0; i--)
     {
-      buffer.append(',');
-      buffer.append(rdnComponents[i].toNormalizedUrlSafeString());
+      buffer.append(',').append(rdnComponents[i].toNormalizedUrlSafeString());
     }
-
     return buffer.toString();
   }
 
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java b/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
index 25c3c6b..36c58f4 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
@@ -66,38 +66,38 @@
         { "DC=COM", "dc=com", "DC=COM" },
         { "dc = com", "dc=com", "dc=com" },
         { " dc = com ", "dc=com", "dc=com" },
-        { "dc=example,dc=com", "dc=example,dc=com", "dc=example,dc=com" },
-        { "dc=example, dc=com", "dc=example,dc=com", "dc=example,dc=com" },
-        { "dc=example ,dc=com", "dc=example,dc=com", "dc=example,dc=com" },
-        { "dc =example , dc  =   com", "dc=example,dc=com", "dc=example,dc=com" },
+        { "dc=example,dc=com", "dc=com,dc=example", "dc=example,dc=com" },
+        { "dc=example, dc=com", "dc=com,dc=example", "dc=example,dc=com" },
+        { "dc=example ,dc=com", "dc=com,dc=example", "dc=example,dc=com" },
+        { "dc =example , dc  =   com", "dc=com,dc=example", "dc=example,dc=com" },
         { "givenName=John+cn=Doe,ou=People,dc=example,dc=com",
-            "cn=doe+givenname=john,ou=people,dc=example,dc=com",
+            "dc=com,dc=example,ou=people,cn=doe+givenname=john",
             "givenName=John+cn=Doe,ou=People,dc=example,dc=com" },
         { "givenName=John\\+cn=Doe,ou=People,dc=example,dc=com",
-            "givenname=john%2Bcn%3Ddoe,ou=people,dc=example,dc=com",
+            "dc=com,dc=example,ou=people,givenname=john%2Bcn%3Ddoe",
             "givenName=John\\+cn=Doe,ou=People,dc=example,dc=com" },
         { "cn=Doe\\, John,ou=People,dc=example,dc=com",
-            "cn=doe%2C%20john,ou=people,dc=example,dc=com",
+            "dc=com,dc=example,ou=people,cn=doe%2C%20john",
             "cn=Doe\\, John,ou=People,dc=example,dc=com" },
         { "UID=jsmith,DC=example,DC=net",
-            "uid=jsmith,dc=example,dc=net",
+            "dc=net,dc=example,uid=jsmith",
             "UID=jsmith,DC=example,DC=net" },
         { "OU=Sales+CN=J. Smith,DC=example,DC=net",
-            "cn=j.%20smith+ou=sales,dc=example,dc=net",
+            "dc=net,dc=example,cn=j.%20smith+ou=sales",
             "OU=Sales+CN=J. Smith,DC=example,DC=net" },
         { "CN=James \\\"Jim\\\" Smith\\, III,DC=example,DC=net",
-            "cn=james%20%22jim%22%20smith%2C%20iii,dc=example,dc=net",
+            "dc=net,dc=example,cn=james%20%22jim%22%20smith%2C%20iii",
             "CN=James \\\"Jim\\\" Smith\\, III,DC=example,DC=net" },
         { "CN=John Smith\\2C III,DC=example,DC=net",
-            "cn=john%20smith%2C%20iii,dc=example,dc=net",
+            "dc=net,dc=example,cn=john%20smith%2C%20iii",
             "CN=John Smith\\, III,DC=example,DC=net" },
         { "CN=\\23John Smith\\20,DC=example,DC=net",
-            "cn=%23john%20smith,dc=example,dc=net",
+            "dc=net,dc=example,cn=%23john%20smith",
             "CN=\\#John Smith\\ ,DC=example,DC=net" },
         { "CN=Before\\0dAfter,DC=example,DC=net",
              //\0d is a hex representation of Carriage return. It is mapped
              //to a SPACE as defined in the MAP ( RFC 4518)
-            "cn=before%20after,dc=example,dc=net",
+            "dc=net,dc=example,cn=before%20after",
             "CN=Before\\0dAfter,DC=example,DC=net" },
         { "1.3.6.1.4.1.1466.0=#04024869",
              //Unicode codepoints from 0000-0008 are mapped to nothing.
@@ -107,13 +107,13 @@
         { "CN=Lu\\C4\\8Di\\C4\\87", "cn=luc%CC%8Cic%CC%81",
             "CN=Lu\u010di\u0107" },
         { "ou=\\e5\\96\\b6\\e6\\a5\\ad\\e9\\83\\a8,o=Airius",
-            "ou=%E5%96%B6%E6%A5%AD%E9%83%A8,o=airius",
+            "o=airius,ou=%E5%96%B6%E6%A5%AD%E9%83%A8",
             "ou=\u55b6\u696d\u90e8,o=Airius" },
-        { "photo=\\ john \\ ,dc=com", "photo=%20john%20%20,dc=com",
+        { "photo=\\ john \\ ,dc=com", "dc=com,photo=%20john%20%20",
             "photo=\\ john \\ ,dc=com" },
         { "AB-global=", "ab-global=", "AB-global=" },
         { "OU= Sales + CN = J. Smith ,DC=example,DC=net",
-            "cn=j.%20smith+ou=sales,dc=example,dc=net",
+            "dc=net,dc=example,cn=j.%20smith+ou=sales",
             "OU=Sales+CN=J. Smith,DC=example,DC=net" },
         { "cn=John+a=", "a=+cn=john", "cn=John+a=" },
         { "OID.1.3.6.1.4.1.1466.0=#04024869",
@@ -121,7 +121,7 @@
             "1.3.6.1.4.1.1466.0=hi",
             "1.3.6.1.4.1.1466.0=\\04\\02Hi" },
         { "O=\"Sue, Grabbit and Runn\",C=US",
-            "o=sue%2C%20grabbit%20and%20runn,c=us",
+            "c=us,o=sue%2C%20grabbit%20and%20runn",
             "O=Sue\\, Grabbit and Runn,C=US" }, };
   }
 
@@ -355,9 +355,9 @@
     DN dn = DN.valueOf("dc=example,dc=com");
 
     assertEquals(dn.toNormalizedByteString(),
-        new ByteStringBuilder().append("dc=com").append(DN.NORMALIZED_RDN_SEPARATOR).append("dc=example")
-        .toByteString());
-    assertEquals(dn.toNormalizedUrlSafeString(), "dc=example,dc=com");
+        new ByteStringBuilder().append("dc=com").append(DN.NORMALIZED_RDN_SEPARATOR)
+                               .append("dc=example").toByteString());
+    assertEquals(dn.toNormalizedUrlSafeString(), "dc=com,dc=example");
   }
 
 

--
Gitblit v1.10.0