You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/11/18 11:55:42 UTC

svn commit: r1542973 - in /myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago: util/HtmlWriterUtilsUnitTest.java webapp/TobagoResponseWriterUnitTest.java

Author: lofwyr
Date: Mon Nov 18 10:55:42 2013
New Revision: 1542973

URL: http://svn.apache.org/r1542973
Log:
TOBAGO-1346: JSON friendly HTML code (change " with ' for attributes)

Modified:
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/HtmlWriterUtilsUnitTest.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/HtmlWriterUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/HtmlWriterUtilsUnitTest.java?rev=1542973&r1=1542972&r2=1542973&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/HtmlWriterUtilsUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/util/HtmlWriterUtilsUnitTest.java Mon Nov 18 10:55:42 2013
@@ -47,7 +47,7 @@ public class HtmlWriterUtilsUnitTest {
   };
   public static final String[] ESCAPED_TEXTS = {
       "oeffnende spitze klammern werden in attributen doch escaped <tagname >",
-      "& followed by an { -> &{ don't get escaped in attributes",
+      "& followed by an { -> &{ don't get escaped in attributes",
       RAW_TEXTS[2], // no escape needed
       " ¡¢£¤¥¦§¨©ª«¬­®¯",
       "°±²³´µ¶·¸¹º»¼½"
@@ -63,21 +63,34 @@ public class HtmlWriterUtilsUnitTest {
   };
 
   public static final String[] ESCAPED_ATTRIBUTES = {
-      "oeffnende spitze klammern werden in attributen doch escaped <tagname >",
-      "& followed by an { -> &{ don't get escaped in attributes",
-      RAW_TEXTS[2] // no escape needed
+      ESCAPED_TEXTS[0], // same as in texts
+      "& followed by an { -> &{ don't get escaped in attributes",
+      ESCAPED_TEXTS[2], // same as in texts
+      ESCAPED_TEXTS[3], // same as in texts
+      ESCAPED_TEXTS[4], // same as in texts
+      ESCAPED_TEXTS[5], // same as in texts
+      ESCAPED_TEXTS[6], // same as in texts
+      ESCAPED_TEXTS[7], // same as in texts
+      ESCAPED_TEXTS[8] // same as in texts
   };
 
   @Test
-  public void test() {
+  public void testTexts() {
     final CharArrayWriter writer = new CharArrayWriter();
     final HtmlWriterUtils helper = new HtmlWriterUtils(writer, "");
 
     for (int i = 0; i < ESCAPED_TEXTS.length; i++) {
       testText(helper, writer, RAW_TEXTS[i], ESCAPED_TEXTS[i]);
-      if (i < ESCAPED_ATTRIBUTES.length) {
-        testAttributeValue(helper, writer, RAW_TEXTS[i], ESCAPED_ATTRIBUTES[i]);
-      }
+    }
+  }
+
+  @Test
+  public void testAttributes() {
+    final CharArrayWriter writer = new CharArrayWriter();
+    final HtmlWriterUtils helper = new HtmlWriterUtils(writer, "");
+
+    for (int i = 0; i < ESCAPED_ATTRIBUTES.length; i++) {
+      testAttributeValue(helper, writer, RAW_TEXTS[i], ESCAPED_ATTRIBUTES[i]);
     }
   }
 
@@ -87,7 +100,7 @@ public class HtmlWriterUtilsUnitTest {
       writer.reset();
       writerUtil.writeText(text);
       final String result = String.valueOf(writer.toCharArray());
-      Assert.assertEquals(result, escaped);
+      Assert.assertEquals(escaped, result);
 
     } catch (final IOException e) {
       // could not occur with CharArrayWriter
@@ -100,7 +113,7 @@ public class HtmlWriterUtilsUnitTest {
       writer.reset();
       writerUtil.writeAttributeValue(text);
       final String result = String.valueOf(writer.toCharArray());
-      Assert.assertEquals(result, escaped);
+      Assert.assertEquals(escaped, result);
 
     } catch (final IOException e) {
       // could not occur with CharArrayWriter

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java?rev=1542973&r1=1542972&r2=1542973&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterUnitTest.java Mon Nov 18 10:55:42 2013
@@ -70,7 +70,7 @@ public class TobagoResponseWriterUnitTes
     writer.startElement(HtmlElements.SELECT, null);
     writer.writeAttribute(HtmlAttributes.VALUE, "0", null);
     writer.endElement(HtmlElements.SELECT);
-    Assert.assertEquals("attr tag", "<select value=\"0\"\n></select>", stringWriter.toString());
+    Assert.assertEquals("attr tag", "<select value='0'\n></select>", stringWriter.toString());
   }
   
   @Test
@@ -78,7 +78,7 @@ public class TobagoResponseWriterUnitTes
     writer.startElement(HtmlElements.A, null);
     writer.writeURIAttribute(HtmlAttributes.HREF, "http://example.org/web?text=äöüß", null);
     writer.endElement(HtmlElements.A);
-    Assert.assertEquals("uri attr tag", "<a href=\"http://example.org/web?text=%C3%A4%C3%B6%C3%BC%C3%9F\"\n></a>",
+    Assert.assertEquals("uri attr tag", "<a href='http://example.org/web?text=%C3%A4%C3%B6%C3%BC%C3%9F'\n></a>",
             stringWriter.toString());
   }
 
@@ -87,7 +87,7 @@ public class TobagoResponseWriterUnitTes
     writer.startElement(HtmlElements.SELECT, null);
     writer.writeAttribute(HtmlAttributes.VALUE, "-<->-ü-€-", null);
     writer.endElement(HtmlElements.SELECT);
-    Assert.assertEquals("attr tag", "<select value=\"-&lt;-&gt;-ü-€-\"\n></select>", stringWriter.toString());
+    Assert.assertEquals("attr tag", "<select value='-&lt;-&gt;-ü-€-'\n></select>", stringWriter.toString());
   }
 
   @Test
@@ -120,10 +120,10 @@ public class TobagoResponseWriterUnitTes
 
     String result = buffer.toString(); // all the same but this 4 items
     result = result.replace("&", "&amp;");
-    result = result.replace("\"", "&quot;");
+    result = result.replace("'", "&#39;");
     result = result.replace("<", "&lt;");
     result = result.replace(">", "&gt;");
-    Assert.assertEquals("all chars", "<select value=\"" + result + "\"\n>" + result + "</select>",
+    Assert.assertEquals("all chars", "<select value='" + result + "'\n>" + result + "</select>",
         stringWriter.toString());
   }
 
@@ -135,7 +135,7 @@ public class TobagoResponseWriterUnitTes
     writer1.writeAttribute(HtmlAttributes.READONLY, true);
     writer1.endElement(HtmlElements.INPUT);
     writer1.close();
-    Assert.assertEquals("<input value=\"Gutschein &uuml;ber 100 &euro;.\" readonly=\"readonly\"\n>",
+    Assert.assertEquals("<input value='Gutschein &uuml;ber 100 &euro;.' readonly='readonly'\n>",
         stringWriter.toString());
   }