Author: vsiveton
Date: Wed May 20 11:34:02 2009
New Revision: 776667

URL: http://svn.apache.org/viewvc?rev=776667&view=rev
Log:
o take care of surrogate

Modified:
    
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
    
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java?rev=776667&r1=776666&r2=776667&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
 Wed May 20 11:34:02 2009
@@ -310,7 +310,7 @@
         StringBuffer encoded = new StringBuffer();
         int length = url.length();
 
-        char[] unicode = new char[1];
+        int[] unicode = new int[1];
 
         for ( int i = 0; i < length; ++i )
         {
@@ -353,7 +353,14 @@
 
                         try
                         {
-                            unicode[0] = c;
+                            if ( isHighSurrogate( c ) )
+                            {
+                                unicode[0] = toCodePoint( c, url.charAt( ++i ) 
);
+                            }
+                            else
+                            {
+                                unicode[0] = c;
+                            }
                             bytes = ( new String( unicode, 0, 1 ) ).getBytes( 
"UTF8" );
                         }
                         catch ( UnsupportedEncodingException cannotHappen )

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java?rev=776667&r1=776666&r2=776667&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java
 Wed May 20 11:34:02 2009
@@ -19,6 +19,9 @@
  * under the License.
  */
 
+import java.net.URLEncoder;
+import java.util.Locale;
+
 import org.codehaus.plexus.PlexusTestCase;
 
 /**
@@ -105,16 +108,18 @@
      * Verify the expected results.
      */
     public void testEncodeURL()
+        throws Exception
     {
         assertNull( HtmlTools.encodeURL( null ) );
         assertEquals( HtmlTools.encodeURL( "" ), "" );
-        assertEquals( HtmlTools.encodeURL(
-            "http://www.example.com/?This is a simple test." ),
-            "http://www.example.com/?This%20is%20a%20simple%20test."; );
-
-        assertEquals( HtmlTools.encodeURL(
-            "http://www.example.com/?This is a simple & short test." ),
-            
"http://www.example.com/?This%20is%20a%20simple%20&%20short%20test."; );
+        assertEquals( HtmlTools.encodeURL( "http://www.example.com/?This is a 
simple test." ),
+                      "http://www.example.com/?This%20is%20a%20simple%20test."; 
);
+
+        assertEquals( HtmlTools.encodeURL( "http://www.example.com/?This is a 
simple & short test." ),
+                      
"http://www.example.com/?This%20is%20a%20simple%20&%20short%20test."; );
+
+        String url = "\uD808\uDF45";
+        assertEquals( HtmlTools.encodeURL( url ), URLEncoder.encode( url, 
"UTF-8" ).toLowerCase( Locale.ENGLISH ) );
     }
 
     /**


Reply via email to