You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2017/07/25 07:27:31 UTC

svn commit: r1802895 - in /myfaces/tobago/branches/tobago-3.0.x: ./ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/ tobago-core/src/main/java/org/apache/myfaces/tobago/util/ tobago-example/tobago-example-demo/src/main/java/org/apac...

Author: hnoeth
Date: Tue Jul 25 07:27:31 2017
New Revision: 1802895

URL: http://svn.apache.org/viewvc?rev=1802895&view=rev
Log:
Merged from trunk
TOBAGO-1769 Ajax doesn't work for text containing unicode characters
* encode method of HtmlResponseWriter copied to XmlResponseWriter
* test added [from revision 1802602]

Added:
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/AjaxUnicodeController.java
      - copied unchanged from r1802602, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/AjaxUnicodeController.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/30-ajax-unicode/
      - copied from r1802602, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/30-ajax-unicode/
Modified:
    myfaces/tobago/branches/tobago-3.0.x/   (props changed)
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/XmlResponseWriter.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java

Propchange: myfaces/tobago/branches/tobago-3.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 25 07:27:31 2017
@@ -1,3 +1,3 @@
 /myfaces/tobago/branches/tobago-1.5.x:1356585,1357124
 /myfaces/tobago/branches/tobago-tree-table:1226794-1341423
-/myfaces/tobago/trunk:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1591854,1600239,1600818,1601860,1602151,1602154,1602343,1604224,1606201,1607642,1609696-1609697,1609718,1610942,1610948,1610970,1610989,1611011,1611259,1611264,1611276,1611329,1611338-1611339,1611571,1613015,1613032,1614827,1614853,1615053,1615114,1615121,1617310,1619789,1621101,1621107,1621134,1621156,1621264,1621282,1621332,1622222,1622243,1622508,1623934,1624033,1625968,1625972,1626270,1628899,1628953,1636842,1636911,1640117,1640147,1640541,1640548,1640638,1640761,1640917,1641575,1641635,1641772,1641775,1641777,1656502,1656507,1657180,1657269,1657276,1657279,1658343,1658909,1658912,1659026,1659031,1660696,1660699,1660708,1660714,1665486,1665521,1665549,1665569-1665570,1666464,1667304,1667306-1667307,1667309,1668147,1668153,1668249,1675330,1675565,1675584,1675588-1675589,1675636,1676030,1676035,1676038,1679031,1680197,1681981,1682187,1682448,1682545,1682548,1683231,1683306,1683373,1683664
 ,1686204,1687354,1693426,1696720,1698292,1698297,1700742,1700795,1701249,1701251,1701256,1701980,1709006,1725894,1726691,1726986,1727161,1731050-1731051,1731054,1731057,1731218-1731219,1780251,1780345,1780393,1780418,1780421,1780519,1781211,1781244,1781273,1788196,1788214-1788215,1788239,1788381,1788484,1790232,1790312,1790315,1798702,1798829-1798830
+/myfaces/tobago/trunk:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1591854,1600239,1600818,1601860,1602151,1602154,1602343,1604224,1606201,1607642,1609696-1609697,1609718,1610942,1610948,1610970,1610989,1611011,1611259,1611264,1611276,1611329,1611338-1611339,1611571,1613015,1613032,1614827,1614853,1615053,1615114,1615121,1617310,1619789,1621101,1621107,1621134,1621156,1621264,1621282,1621332,1622222,1622243,1622508,1623934,1624033,1625968,1625972,1626270,1628899,1628953,1636842,1636911,1640117,1640147,1640541,1640548,1640638,1640761,1640917,1641575,1641635,1641772,1641775,1641777,1656502,1656507,1657180,1657269,1657276,1657279,1658343,1658909,1658912,1659026,1659031,1660696,1660699,1660708,1660714,1665486,1665521,1665549,1665569-1665570,1666464,1667304,1667306-1667307,1667309,1668147,1668153,1668249,1675330,1675565,1675584,1675588-1675589,1675636,1676030,1676035,1676038,1679031,1680197,1681981,1682187,1682448,1682545,1682548,1683231,1683306,1683373,1683664
 ,1686204,1687354,1693426,1696720,1698292,1698297,1700742,1700795,1701249,1701251,1701256,1701980,1709006,1725894,1726691,1726986,1727161,1731050-1731051,1731054,1731057,1731218-1731219,1780251,1780345,1780393,1780418,1780421,1780519,1781211,1781244,1781273,1788196,1788214-1788215,1788239,1788381,1788484,1790232,1790312,1790315,1798702,1798829-1798830,1802602

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/XmlResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/XmlResponseWriter.java?rev=1802895&r1=1802894&r2=1802895&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/XmlResponseWriter.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/XmlResponseWriter.java Tue Jul 25 07:27:31 2017
@@ -42,7 +42,7 @@ public final class XmlResponseWriter ext
       throws IOException {
     closeOpenTag();
     final String value = findValue(text, property);
-    write(XmlUtils.escape(value));
+    write(XmlUtils.encode(value, false));
   }
 
   @Override
@@ -75,7 +75,7 @@ public final class XmlResponseWriter ext
 
   @Override
   protected void writerAttributeValue(final String value, final boolean escape) throws IOException {
-    getWriter().write(XmlUtils.escape(value));
+    getWriter().write(XmlUtils.encode(value, true));
   }
 
   @Override

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java?rev=1802895&r1=1802894&r2=1802895&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java Tue Jul 25 07:27:31 2017
@@ -37,9 +37,91 @@ import java.util.Properties;
 
 public final class XmlUtils {
 
+  private static final char[][] CHARS_TO_ESCAPE;
+  private static final char[] EMPTY = new char[0];
+
+  static {
+    // init lookup table
+    CHARS_TO_ESCAPE = new char[0xA0][];
+
+    for (int i = 0; i < 0x20; i++) {
+      CHARS_TO_ESCAPE[i] = EMPTY; // Control characters
+    }
+
+    CHARS_TO_ESCAPE['\t'] = "&#x09;".toCharArray(); // Horizontal tabulator
+    CHARS_TO_ESCAPE['\n'] = "&#x0a;".toCharArray(); // Line feed
+    CHARS_TO_ESCAPE['\r'] = "&#x0d;".toCharArray(); // Carriage return
+
+    CHARS_TO_ESCAPE['\''] = "&#x27;".toCharArray();
+    CHARS_TO_ESCAPE['\"'] = "&quot;".toCharArray();
+    CHARS_TO_ESCAPE['&'] = "&amp;".toCharArray();
+    CHARS_TO_ESCAPE['<'] = "&lt;".toCharArray();
+    CHARS_TO_ESCAPE['>'] = "&gt;".toCharArray();
+    CHARS_TO_ESCAPE['/'] = "&#x2F;".toCharArray();
+
+    CHARS_TO_ESCAPE[0x7F] = EMPTY; // Delete
+
+    for (int i = 0x80; i < 0xA0; i++) {
+      CHARS_TO_ESCAPE[i] = EMPTY; // Control characters
+    }
+
+    // all "normal" character positions contains null
+  }
+
   private XmlUtils() {
   }
 
+  public static String encode(final String s, final boolean isAttribute) {
+    StringBuilder stringBuilder = new StringBuilder();
+
+    final char[] text = s.toCharArray();
+    final int start = 0;
+    final int length = s.length();
+
+    int localIndex = -1;
+
+    final int end = start + length;
+    for (int i = start; i < end; i++) {
+      final char ch = text[i];
+      if (ch >= CHARS_TO_ESCAPE.length || CHARS_TO_ESCAPE[ch] != null) {
+        localIndex = i;
+        break;
+      }
+    }
+
+    if (localIndex == -1) {
+      // no need to escape
+      return s;
+    } else {
+      // write until localIndex and then encode the remainder
+      stringBuilder.append(text, start, localIndex);
+
+      for (int i = localIndex; i < end; i++) {
+        final char ch = text[i];
+
+        // Tilde or less...
+        if (ch < CHARS_TO_ESCAPE.length) {
+          if (isAttribute && ch == '&' && (i + 1 < end) && text[i + 1] == '{') {
+            // HTML 4.0, section B.7.1: ampersands followed by
+            // an open brace don't get escaped
+            stringBuilder.append('&');
+          } else if (CHARS_TO_ESCAPE[ch] != null) {
+            stringBuilder.append(CHARS_TO_ESCAPE[ch]);
+          } else {
+            stringBuilder.append(ch);
+          }
+        } else {
+          // Double-byte characters to encode.
+          // PENDING: when outputting to an encoding that
+          // supports double-byte characters (UTF-8, for example),
+          // we should not be encoding
+          stringBuilder.append(ch);
+        }
+      }
+    }
+    return stringBuilder.toString();
+  }
+
   public static String escape(final String s) {
     return escape(s, true);
   }

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java?rev=1802895&r1=1802894&r2=1802895&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java Tue Jul 25 07:27:31 2017
@@ -426,4 +426,10 @@ public class QUnitTests {
     String page = "content/40-test/50000-java/20-ajax-execute/ajax-execute.xhtml";
     runStandardTest(page);
   }
+
+  @Test
+  public void ajaxUnicode() throws UnsupportedEncodingException, InterruptedException {
+    String page = "content/40-test/50000-java/30-ajax-unicode/ajax-unicode.xhtml";
+    runStandardTest(page);
+  }
 }