cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1765804 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/serializers: java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java test/org/apache/cocoon/components/serializers/encoding/XMLEncoderTestCase.java
Date Thu, 20 Oct 2016 11:40:58 GMT
Author: ilgrosso
Date: Thu Oct 20 11:40:57 2016
New Revision: 1765804

URL: http://svn.apache.org/viewvc?rev=1765804&view=rev
Log:
[COCOON-2352] Third PR applied - This closes #3

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/test/org/apache/cocoon/components/serializers/encoding/XMLEncoderTestCase.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java?rev=1765804&r1=1765803&r2=1765804&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
Thu Oct 20 11:40:57 2016
@@ -98,12 +98,15 @@ public class XMLEncoder extends Compiled
             }
             int codePoint = Character.toCodePoint(highSurrogate.charValue(), c);
             highSurrogate = null;
-            return encode((char) codePoint);
+            return encode(codePoint);
         } else if (Character.isHighSurrogate(c)) {
             highSurrogate = Character.valueOf(c);
             return new char[0];
         }
-        
+        return encode((int) c);
+    }
+    
+    private char[] encode(int c) {
         switch (c) {
             case 0x22: return(ENCODE_QUOT); // (") ["]
             case 0x26: return(ENCODE_AMP);  // (&) [&]
@@ -111,6 +114,16 @@ public class XMLEncoder extends Compiled
             case 0x3c: return(ENCODE_LT);   // (<) [&lt;]
             case 0x3e: return(ENCODE_GT);   // (>) [&gt;]
             default: {
+                if (c > 0xffff) {
+                    char ret[] = { '&', '#', 'x',
+                        ENCODE_HEX[c >> 0x10 & 0xf],
+                        ENCODE_HEX[c >> 0xc & 0xf],
+                        ENCODE_HEX[c >> 0x8 & 0xf],
+                        ENCODE_HEX[c >> 0x4 & 0xf],
+                        ENCODE_HEX[c & 0xf], ';'
+                    };
+                    return(ret);
+                }
                 if (c > 0xfff) {
                     char ret[] = { '&', '#', 'x',
                         ENCODE_HEX[c >> 0xc & 0xf],

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/test/org/apache/cocoon/components/serializers/encoding/XMLEncoderTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/test/org/apache/cocoon/components/serializers/encoding/XMLEncoderTestCase.java?rev=1765804&r1=1765803&r2=1765804&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/test/org/apache/cocoon/components/serializers/encoding/XMLEncoderTestCase.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/test/org/apache/cocoon/components/serializers/encoding/XMLEncoderTestCase.java
Thu Oct 20 11:40:57 2016
@@ -37,8 +37,7 @@ public class XMLEncoderTestCase extends
      * Test COCOON-2352: XMLEncoder doesn't support Unicode surrogate pairs.
      */
     public void testEncodingSurrogatePairs() {
-        char[] expectedValue = encoder.encode((char) 127808);
-
+        char[] expectedValue = "&#x1F340;".toCharArray();
         assertTrue(encoder.encode('\uD83C').length == 0);
         assertTrue(Arrays.equals(expectedValue, encoder.encode('\uDF40')));
     }



Mime
View raw message