You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2004/01/10 03:58:36 UTC

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringEscapeUtilsTest.java

ggregory    2004/01/09 18:58:36

  Modified:    lang/src/java/org/apache/commons/lang Entities.java
               lang/src/test/org/apache/commons/lang
                        StringEscapeUtilsTest.java
  Log:
  PR: 25227
  Obtained from: Discussion around http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25227
  
  Revision  Changes    Path
  1.16      +7 -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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Entities.java	13 Sep 2003 03:11:29 -0000	1.15
  +++ Entities.java	10 Jan 2004 02:58:36 -0000	1.16
  @@ -687,7 +687,12 @@
                   String entityName = str.substring(i + 1, semi);
                   int entityValue;
                   if (entityName.charAt(0) == '#') {
  -                    entityValue = Integer.parseInt(entityName.substring(1));
  +                    char charAt1 = entityName.charAt(1);
  +                    if (charAt1 == 'x' || charAt1=='X') {
  +                        entityValue = Integer.valueOf(entityName.substring(2), 16).intValue();
  +                    } else {
  +                        entityValue = Integer.parseInt(entityName.substring(1));
  +                    }
                   } else {
                       entityValue = this.entityValue(entityName);
                   }
  
  
  
  1.13      +17 -2     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- StringEscapeUtilsTest.java	18 Aug 2003 02:22:25 -0000	1.12
  +++ StringEscapeUtilsTest.java	10 Jan 2004 02:58:36 -0000	1.13
  @@ -262,8 +262,23 @@
           }
           // \u00E7 is a cedilla (c with wiggle under)
           // note that the test string must be 7-bit-clean (unicode escaped) or else it will compile incorrectly
  -        // on some locales
  +        // on some locales        
           assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml("Fran\u00E7ais"));
  +    }
  +
  +    public void testUnescapeHexCharsHtml() {
  +        // Simple easy to grok test 
  +        assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml("€Ÿ"));
  +        assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml("€Ÿ"));
  +        // Test all Character values:
  +        for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
  +            Character c1 = new Character(i);
  +            Character c2 = new Character((char)(i+1));
  +            String expected = c1.toString() + c2.toString();
  +            String escapedC1 = "&#x" + Integer.toHexString((int)(c1.charValue())) + ";";
  +            String escapedC2 = "&#x" + Integer.toHexString((int)(c2.charValue())) + ";";
  +            assertEquals("hex number unescape index " + (int)i, expected, StringEscapeUtils.unescapeHtml(escapedC1 + escapedC2));
  +        }
       }
   
       public void testUnescapeUnknownEntity() throws Exception
  
  
  

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