8032909: XSLT string-length returns incorrect length when string includes complementary chars

Reviewed-by: joehw, dfuchs
This commit is contained in:
Aleksei Efimov 2014-02-21 16:57:21 +04:00
parent 43d3e02a42
commit 2c18d040ba
2 changed files with 13 additions and 3 deletions

View File

@ -26,7 +26,7 @@ package com.sun.org.apache.xalan.internal.xsltc.compiler;
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 @@ final class StringLengthCall extends FunctionCall {
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")));
}
}

View File

@ -1660,5 +1660,14 @@ public final class BasisLibrary {
}
/**
* 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
}