You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2006/09/11 05:19:58 UTC

svn commit: r442081 - /xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java

Author: mrglavas
Date: Sun Sep 10 20:19:57 2006
New Revision: 442081

URL: http://svn.apache.org/viewvc?view=rev&rev=442081
Log:
Bug Fixes:
- '<' must always be escaped in a well-formed attribute value
- 0x09, 0x0A and 0x0D must be escaped in attribute values so 
  that they may be round-tripped. They would otherwise be 
  transformed to 0x20 during attribute value normalization.

Performance Fix:
- if an attribute value doesn't contain any characters
  which need to be escaped avoid creating a new string

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java?view=diff&rev=442081&r1=442080&r2=442081
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java Sun Sep 10 20:19:57 2006
@@ -43,7 +43,7 @@
 
 /**
  * Class <code>XSDAbstractTraverser</code> serves as the base class for all
- * other <code>XSD???Traverser</code>s. It holds the common data and provide
+ * other <code>XSD???Traverser</code>s. It holds the common data and provides
  * a unified way to initialize these data.
  *
  * @xerces.internal 
@@ -161,7 +161,7 @@
                 localStrBuffer.append(rawname)
                 .append("=\"");
                 String value = (String)annotationLocalAttrs.elementAt(i++);
-                // search for pesky "s and >s within attr value:
+                // search for pesky "s and <s within attr value:
                 value = processAttValue(value);
                 localStrBuffer.append(value)
                 .append("\" ");
@@ -220,7 +220,7 @@
                 localStrBuffer.append(rawname)
                 .append("=\"");
                 String value = (String)annotationLocalAttrs.elementAt(i++);
-                // search for pesky "s and >s within attr value:
+                // search for pesky "s and <s within attr value:
                 value = processAttValue(value);
                 localStrBuffer.append(value)
                 .append("\" ");
@@ -732,19 +732,49 @@
         return particle;
     }
     
-    // this is not terribly performant!
     private static String processAttValue(String original) {
+        final int length = original.length();
         // normally, nothing will happen
-        StringBuffer newVal = new StringBuffer(original.length());
-        for(int i=0; i<original.length(); i++) {
+        for (int i = 0; i < length; ++i) {
+            char currChar = original.charAt(i);
+            if (currChar == '"' || currChar == '<' || currChar == '&' ||
+                    currChar == 0x09 || currChar == 0x0A || currChar == 0x0D) {
+                return escapeAttValue(original, i);
+            }
+        }
+        return original;
+    }
+    
+    // this is not terribly performant!
+    private static String escapeAttValue(String original, int from) {
+        int i;
+        final int length = original.length();
+        StringBuffer newVal = new StringBuffer(length);
+        newVal.append(original.substring(0, from));
+        for (i = from; i < length; ++i) {
             char currChar = original.charAt(i);
-            if(currChar == '"') {
+            if (currChar == '"') {
                 newVal.append("&quot;");
-            } else if (currChar == '>') {
-                newVal.append("&gt;");
-            } else if (currChar == '&') {
+            } 
+            else if (currChar == '<') {
+                newVal.append("&lt;");
+            }
+            else if (currChar == '&') {
                 newVal.append("&amp;");
-            } else {
+            }
+            // Must escape 0x09, 0x0A and 0x0D if they appear in attribute
+            // value so that they may be round-tripped. They would otherwise
+            // be transformed to a 0x20 during attribute value normalization.
+            else if (currChar == 0x09) {
+                newVal.append("&#x9;");
+            }
+            else if (currChar == 0x0A) {
+                newVal.append("&#xA;");
+            }
+            else if (currChar == 0x0D) {
+                newVal.append("&#xD;");
+            }
+            else {
                 newVal.append(currChar);
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org