commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringEscapeUtilsTest.java
Date Wed, 09 Apr 2003 21:30:18 GMT
alex        2003/04/09 14:30:18

  Modified:    lang/src/java/org/apache/commons/lang Entities.java
                        StringEscapeUtils.java
               lang/src/test/org/apache/commons/lang
                        StringEscapeUtilsTest.java
  Log:
  improving javadoc
  added apos entity to XML escape/unescape
  add test for "unknown entity" behavior
  
  Revision  Changes    Path
  1.2       +9 -2      jakarta-commons/lang/src/java/org/apache/commons/lang/Entities.java
  
  Index: Entities.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/Entities.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Entities.java	9 Apr 2003 20:55:32 -0000	1.1
  +++ Entities.java	9 Apr 2003 21:30:18 -0000	1.2
  @@ -69,7 +69,9 @@
    * <a href="http://hotwired.lycos.com/webmonkey/reference/special_characters/">WebMonkey</a>
    * <a href="http://www.w3.org/TR/REC-html32#latin1">HTML 3.2</a>
    * <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html</a>HTML 4.0</a>
  - * </p>
  + * <a href="http://www.w3.org/TR/html401/charset.html#h-5.3"</a>Character references</a>
  + * <a href="http://www.w3.org/TR/html401/charset.html#code-position</a>HTML 4.0:
code positions</a>
  +/p>
    *
    * @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
    * @since 2.0
  @@ -84,6 +86,10 @@
           {"gt", "62"}, // > - greater-than
       };
   
  +    static private Object[][] apos = {
  +        {"apos", "39"}, // XML apostrophe
  +    };
  +
       static private Object[][] iso8859_1 = {
           {"nbsp", "160"}, // non-breaking space
           {"iexcl", "161"}, //inverted exclamation mark
  @@ -375,6 +381,7 @@
       static {
           XML = new Entities();
           XML.addEntities(basic);
  +        XML.addEntities(apos);
       }
   
       static {
  
  
  
  1.7       +17 -6     jakarta-commons/lang/src/java/org/apache/commons/lang/StringEscapeUtils.java
  
  Index: StringEscapeUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringEscapeUtils.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StringEscapeUtils.java	9 Apr 2003 20:55:32 -0000	1.6
  +++ StringEscapeUtils.java	9 Apr 2003 21:30:18 -0000	1.7
  @@ -362,9 +362,14 @@
        * For example: <tt>"bread" & "butter"</tt> => <tt>&amp;quot;bread&amp;quot;
&amp;amp; &amp;quot;butter&amp;quot;</tt>.
        * </p>
        * <p>Supports all known HTML 4.0 entities, including funky accents.
  -     * See the source code for more detail.
        * </p>
  -     * @see http://hotwired.lycos.com/webmonkey/reference/special_characters/
  +     * <p>
  +     * See <a href="http://hotwired.lycos.com/webmonkey/reference/special_characters/">WebMonkey</a>
  +     * <a href="http://www.w3.org/TR/REC-html32#latin1">HTML 3.2</a>
  +     * <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html</a>HTML 4.0</a>
  +     * <a href="http://www.w3.org/TR/html401/charset.html#h-5.3"</a>Character
references</a>
  +     * <a href="http://www.w3.org/TR/html401/charset.html#code-position</a>HTML
4.0: code positions</a>
  +     * </p>
        * @see Entities
        * @see #unescapeHtml(String)
        **/
  @@ -373,9 +378,14 @@
       }
   
       /**
  -     * Given a string containing entity escapes, returns a string
  +     * <p>Given a string containing entity escapes, returns a string
        * containing the actual Unicode characters corresponding to the
  -     * escapes.
  +     * escapes.  Supports HTML 4.0 entities.</p>
  +     * <p>For example, the string "&amp;lt;Fran&ccedilla;ais&amp;gt;"
  +     * will become "<Fran\u00E7ais>"</p>
  +     * <p>If an entity is unrecognized, it is left alone, and inserted
  +     * verbatim into the result string. e.g. "&amp;gt;&amp;zzzz;x" will
  +     * become "&gt;&amp;zzzz;x".</p>
        *
        * @see #escapeHtml(String)
        **/
  @@ -386,7 +396,8 @@
       /**
        * <p>Turns funky characters into XML entity equivalents.</p>
        * <p>
  -     * For example: <tt>"bread" & "butter"</tt> => <tt>&amp;quot;bread&amp;quot;
&amp;amp; &amp;quot;butter&amp;quot;</tt>.
  +     * For example: <tt>"bread" & "butter"</tt> =>
  +     * <tt>&amp;quot;bread&amp;quot; &amp;amp; &amp;quot;butter&amp;quot;</tt>.
        * </p>
        * <p>
        * Supports only the four basic XML entities (gt, lt, quot, amp).
  
  
  
  1.5       +10 -3     jakarta-commons/lang/src/test/org/apache/commons/lang/StringEscapeUtilsTest.java
  
  Index: StringEscapeUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringEscapeUtilsTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StringEscapeUtilsTest.java	9 Apr 2003 20:55:33 -0000	1.4
  +++ StringEscapeUtilsTest.java	9 Apr 2003 21:30:18 -0000	1.5
  @@ -201,6 +201,11 @@
           assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml("Fran\u00E7ais"));
       }
   
  +    public void testUnescapeUnknownEntity() throws Exception
  +    {
  +        assertEquals("&zzzz;", StringEscapeUtils.unescapeHtml("&zzzz;"));
  +    }
  +
       public void testEscapeHtmlVersions() throws Exception
       {
           assertEquals("&Beta;", StringEscapeUtils.escapeHtml("\u0392"));
  @@ -218,13 +223,15 @@
                   "&#161;", StringEscapeUtils.escapeXml("\u00A1"));
           assertEquals("XML should use numbers, not names for HTML entities",
                   "\u00A0", StringEscapeUtils.unescapeXml("&#160;"));
  +
  +        assertEquals("ain't", StringEscapeUtils.unescapeXml("ain&apos;t"));
  +        assertEquals("ain&apos;t", StringEscapeUtils.escapeXml("ain't"));
       }
   
       // SQL
       // see http://www.jguru.com/faq/view.jsp?EID=8881
       //--------------------
  -//    public void testEscapeSQL() throws Exception {
       // sql doubles-up single-quotes
  -//    }
  +    //}
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message