cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1764605 - in /cocoon/subprojects/cocoon-serializers-charsets/trunk: ./ src/main/java/org/apache/cocoon/components/serializers/encoding/ src/main/java/org/apache/cocoon/components/serializers/util/ src/test/ src/test/java/ src/test/java/org...
Date Thu, 13 Oct 2016 06:45:49 GMT
Author: ilgrosso
Date: Thu Oct 13 06:45:49 2016
New Revision: 1764605

URL: http://svn.apache.org/viewvc?rev=1764605&view=rev
Log:
[COCOON-2352] Reworking the provided patch for cocoon-serializers-charsets

Added:
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
  (with props)
Modified:
    cocoon/subprojects/cocoon-serializers-charsets/trunk/   (props changed)
    cocoon/subprojects/cocoon-serializers-charsets/trunk/pom.xml
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
    cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java

Propchange: cocoon/subprojects/cocoon-serializers-charsets/trunk/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 13 06:45:49 2016
@@ -0,0 +1 @@
+target

Modified: cocoon/subprojects/cocoon-serializers-charsets/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/subprojects/cocoon-serializers-charsets/trunk/pom.xml?rev=1764605&r1=1764604&r2=1764605&view=diff
==============================================================================
--- cocoon/subprojects/cocoon-serializers-charsets/trunk/pom.xml (original)
+++ cocoon/subprojects/cocoon-serializers-charsets/trunk/pom.xml Thu Oct 13 06:45:49 2016
@@ -18,8 +18,8 @@
   under the License.
 -->
 <!--+
-    | @version $Id$
-    +-->
+| @version $Id$
++-->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
   <modelVersion>4.0.0</modelVersion>  
@@ -57,6 +57,12 @@
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
     </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
URL: http://svn.apache.org/viewvc/cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java?rev=1764605&r1=1764604&r2=1764605&view=diff
==============================================================================
--- cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
(original)
+++ cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/encoding/XMLEncoder.java
Thu Oct 13 06:45:49 2016
@@ -30,6 +30,8 @@ public class XMLEncoder extends Compiled
     private static final char ENCODE_LT[]   = "&lt;".toCharArray();
     private static final char ENCODE_GT[]   = "&gt;".toCharArray();
 
+    private Character highSurrogate = null;
+    
     /**
      * Create a new instance of this <code>XMLEncoder</code>.
      */
@@ -47,6 +49,10 @@ public class XMLEncoder extends Compiled
         super(name);
     }
     
+    public void reset() {
+        this.highSurrogate = null;
+    }
+      
     /**
      * Return true or false wether this encoding can encode the specified
      * character or not.
@@ -85,6 +91,18 @@ public class XMLEncoder extends Compiled
      * specified character.
      */
     public char[] encode(char c) {
+        if (highSurrogate != null) {
+            if (!Character.isLowSurrogate(c)) {
+                throw new IllegalArgumentException("Expected low surrogate char");
+            }
+            int codePoint = Character.toCodePoint(highSurrogate, c);
+            highSurrogate = null;
+            return new char[] { (char) codePoint };
+        } else if (Character.isHighSurrogate(c)) {
+            highSurrogate = c;
+            return new char[0];
+        }
+
         switch (c) {
             case 0x22: return(ENCODE_QUOT); // (") [&quot;]
             case 0x26: return(ENCODE_AMP);  // (&) [&amp;]

Modified: cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java?rev=1764605&r1=1764604&r2=1764605&view=diff
==============================================================================
--- cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java
(original)
+++ cocoon/subprojects/cocoon-serializers-charsets/trunk/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java
Thu Oct 13 06:45:49 2016
@@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletReq
 import org.apache.cocoon.components.serializers.encoding.Charset;
 import org.apache.cocoon.components.serializers.encoding.CharsetFactory;
 import org.apache.cocoon.components.serializers.encoding.Encoder;
+import org.apache.cocoon.components.serializers.encoding.XMLEncoder;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
@@ -149,11 +150,16 @@ public abstract class EncodingSerializer
      * Reset this <code>EncodingSerializer</code>.
      */
     public void recycle() {
-        if (processing) throw new IllegalStateException();
+        if (processing) {
+            throw new IllegalStateException();
+        }
         this.namespaces = new Namespaces();
         this.locator = null;
         this.out = null;
         this.prolog = true;
+        if (this.encoder instanceof XMLEncoder) {
+            ((XMLEncoder) this.encoder).reset();
+        }
     }
 
     /**

Added: cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java?rev=1764605&view=auto
==============================================================================
--- cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
(added)
+++ cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
Thu Oct 13 06:45:49 2016
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.components.serializers.encoding;
+
+import static junit.framework.Assert.assertTrue;
+
+import java.util.Arrays;
+import org.junit.Test;
+
+public class XMLEncoderTest {
+
+    private final XMLEncoder encoder = new XMLEncoder();
+
+    /**
+     * Test COCOON-2352: XMLEncoder doesn't support Unicode surrogate pairs.
+     */
+    @Test
+    public void encodingSurrogatePairs() {
+        assertTrue(encoder.encode('\uD83C').length == 0);
+
+        assertTrue(Arrays.equals(new char[] { (char) 127808 }, encoder.encode('\uDF40')));
+    }
+}

Propchange: cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: cocoon/subprojects/cocoon-serializers-charsets/trunk/src/test/java/org/apache/cocoon/components/serializers/encoding/XMLEncoderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message