commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt TestXMLUtils.java
Date Mon, 26 May 2003 10:46:59 GMT
rdonkin     2003/05/26 03:46:58

  Modified:    betwixt/src/java/org/apache/commons/betwixt XMLUtils.java
               betwixt/src/test/org/apache/commons/betwixt
                        TestXMLUtils.java
  Log:
  Fixed attribute escaping bug caused by using the wrong length for the ' entity.
Also, new test for attribute escaping. Submitted by Larry Young.
  
  Revision  Changes    Path
  1.4       +7 -7      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLUtils.java
  
  Index: XMLUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLUtils.java	20 Feb 2003 18:06:59 -0000	1.3
  +++ XMLUtils.java	26 May 2003 10:46:57 -0000	1.4
  @@ -362,8 +362,8 @@
                       break;
                    case '\'':
                       buffer.replace(i, i+1, APOSTROPHE_ENTITY);
  -                    size += 4;
  -                    i += 4;
  +                    size += 5;
  +                    i += 5;
                       break;
                    case '\"':
                       buffer.replace(i, i+1, QUOTE_ENTITY);
  
  
  
  1.2       +39 -5     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestXMLUtils.java
  
  Index: TestXMLUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestXMLUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXMLUtils.java	19 Jan 2003 23:21:31 -0000	1.1
  +++ TestXMLUtils.java	26 May 2003 10:46:58 -0000	1.2
  @@ -99,5 +99,39 @@
           assertEquals("Testing name '_Name'", true, XMLUtils.isWellFormedXMLName("_Name"));
           assertEquals("Testing name 'A0123456789Name", true, XMLUtils.isWellFormedXMLName("A0123456789Name"));
       }
  +    
  +    /** Test attribute escaping */
  +    public void testAttributeEscaping() {
  +        assertEquals("Escaping: <", "&lt;", XMLUtils.escapeAttributeValue("<"));
  +        assertEquals("Escaping: >", "&gt;", XMLUtils.escapeAttributeValue(">"));
  +        assertEquals("Escaping: '", "&apos;", XMLUtils.escapeAttributeValue("'"));
  +        assertEquals("Escaping: \"", "&quot;", XMLUtils.escapeAttributeValue("\""));
  +        assertEquals("Escaping: &", "&amp;", XMLUtils.escapeAttributeValue("&"));
  +        assertEquals("Escaping: 1<", "1&lt;", XMLUtils.escapeAttributeValue("1<"));
  +        assertEquals("Escaping: 1>", "1&gt;", XMLUtils.escapeAttributeValue("1>"));
  +        assertEquals("Escaping: 1'", "1&apos;", XMLUtils.escapeAttributeValue("1'"));
  +        assertEquals("Escaping: 1\"", "1&quot;", XMLUtils.escapeAttributeValue("1\""));
  +        assertEquals("Escaping: 1&", "1&amp;", XMLUtils.escapeAttributeValue("1&"));
  +        assertEquals("Escaping: <2", "&lt;2", XMLUtils.escapeAttributeValue("<2"));
  +        assertEquals("Escaping: >2", "&gt;2", XMLUtils.escapeAttributeValue(">2"));
  +        assertEquals("Escaping: '2", "&apos;2", XMLUtils.escapeAttributeValue("'2"));
  +        assertEquals("Escaping: \"2", "&quot;2", XMLUtils.escapeAttributeValue("\"2"));
  +        assertEquals("Escaping: &2", "&amp;2", XMLUtils.escapeAttributeValue("&2"));
  +        assertEquals("Escaping: a<b", "a&lt;b", XMLUtils.escapeAttributeValue("a<b"));
  +        assertEquals("Escaping: a>b", "a&gt;b", XMLUtils.escapeAttributeValue("a>b"));
  +        assertEquals("Escaping: a'b", "a&apos;b", XMLUtils.escapeAttributeValue("a'b"));
  +        assertEquals("Escaping: a\"b", "a&quot;b", XMLUtils.escapeAttributeValue("a\"b"));
  +        assertEquals("Escaping: a&b", "a&amp;b", XMLUtils.escapeAttributeValue("a&b"));
  +        assertEquals("Escaping: <<abba", "&lt;&lt;abba", XMLUtils.escapeAttributeValue("<<abba"));
  +        assertEquals("Escaping: >>abba", "&gt;&gt;abba", XMLUtils.escapeAttributeValue(">>abba"));
  +        assertEquals("Escaping: ''abba", "&apos;&apos;abba", XMLUtils.escapeAttributeValue("''abba"));
  +        assertEquals("Escaping: \"\"abba", "&quot;&quot;abba", XMLUtils.escapeAttributeValue("\"\"abba"));
  +        assertEquals("Escaping: &&abba", "&amp;&amp;abba", XMLUtils.escapeAttributeValue("&&abba"));
  +        assertEquals(
  +            "Escaping: a<>b''c\"e>f'&g", 
  +            "a&lt;&gt;b&apos;&apos;c&quot;e&gt;f&apos;&amp;g",

  +            XMLUtils.escapeAttributeValue("a<>b''c\"e>f'&g"));
  +        
  +    }
   }
   
  
  
  

---------------------------------------------------------------------
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