mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 20:14:43 +02:00
8074297: substring in XSLT returns wrong character if string contains supplementary chars
Reviewed-by: joehw
This commit is contained in:
parent
b2805ba95a
commit
d4502a832f
1 changed files with 11 additions and 6 deletions
|
@ -270,7 +270,7 @@ public final class BasisLibrary {
|
||||||
if (Double.isNaN(start))
|
if (Double.isNaN(start))
|
||||||
return(EMPTYSTRING);
|
return(EMPTYSTRING);
|
||||||
|
|
||||||
final int strlen = value.length();
|
final int strlen = getStringLength(value);
|
||||||
int istart = (int)Math.round(start) - 1;
|
int istart = (int)Math.round(start) - 1;
|
||||||
|
|
||||||
if (istart > strlen)
|
if (istart > strlen)
|
||||||
|
@ -278,6 +278,7 @@ public final class BasisLibrary {
|
||||||
if (istart < 1)
|
if (istart < 1)
|
||||||
istart = 0;
|
istart = 0;
|
||||||
try {
|
try {
|
||||||
|
istart = value.offsetByCodePoints(0, istart);
|
||||||
return value.substring(istart);
|
return value.substring(istart);
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
|
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
|
||||||
|
@ -297,13 +298,14 @@ public final class BasisLibrary {
|
||||||
return(EMPTYSTRING);
|
return(EMPTYSTRING);
|
||||||
|
|
||||||
int istart = (int)Math.round(start) - 1;
|
int istart = (int)Math.round(start) - 1;
|
||||||
|
final int ilength = (int)Math.round(length);
|
||||||
final int isum;
|
final int isum;
|
||||||
if (Double.isInfinite(length))
|
if (Double.isInfinite(length))
|
||||||
isum = Integer.MAX_VALUE;
|
isum = Integer.MAX_VALUE;
|
||||||
else
|
else
|
||||||
isum = istart + (int)Math.round(length);
|
isum = istart + ilength;
|
||||||
|
|
||||||
final int strlen = value.length();
|
final int strlen = getStringLength(value);
|
||||||
if (isum < 0 || istart > strlen)
|
if (isum < 0 || istart > strlen)
|
||||||
return(EMPTYSTRING);
|
return(EMPTYSTRING);
|
||||||
|
|
||||||
|
@ -311,10 +313,13 @@ public final class BasisLibrary {
|
||||||
istart = 0;
|
istart = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isum > strlen)
|
istart = value.offsetByCodePoints(0, istart);
|
||||||
|
if (isum > strlen) {
|
||||||
return value.substring(istart);
|
return value.substring(istart);
|
||||||
else
|
} else {
|
||||||
return value.substring(istart, isum);
|
int offset = value.offsetByCodePoints(istart, ilength);
|
||||||
|
return value.substring(istart, offset);
|
||||||
|
}
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
|
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue