changeset 1151:10482e99b051

8032909: XSLT string-length returns incorrect length when string includes complementary chars Reviewed-by: joehw, dfuchs
author aefimov
date Fri, 21 Feb 2014 16:57:21 +0400
parents 8c96b989c6b6
children c650960636eb
files src/com/sun/org/apache/xalan/internal/xsltc/compiler/StringLengthCall.java src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StringLengthCall.java	Mon Mar 24 18:40:19 2014 +0400
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StringLengthCall.java	Fri Feb 21 16:57:21 2014 +0400
@@ -26,7 +26,7 @@
 import java.util.Vector;
 
 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
-import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
+import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
 import com.sun.org.apache.bcel.internal.generic.InstructionList;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
@@ -51,7 +51,8 @@
             il.append(methodGen.loadContextNode());
             Type.Node.translateTo(classGen, methodGen, Type.String);
         }
-        il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
-                                                     "length", "()I")));
+        il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
+                                                     "getStringLength",
+                                                     "(Ljava/lang/String;)I")));
     }
 }
--- a/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java	Mon Mar 24 18:40:19 2014 +0400
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java	Fri Feb 21 16:57:21 2014 +0400
@@ -1660,5 +1660,14 @@
 
     }
 
+    /**
+     *  Utility method to calculate string-length as a number of code points,
+     *  to avoid possible errors with string that contains
+     *  complementary characters
+     */
+    public static int getStringLength(String str) {
+        return str.codePointCount(0,str.length());
+    }
+
     //-- End utility functions
 }