Skip to content

Commit

Permalink
Further simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 7, 2023
1 parent eb5189d commit c57023d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/com/ctc/wstx/sr/StreamScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ protected int resolveSimpleEntity(boolean checkStd)
char[] buf = mInputBuffer;
int ptr = mInputPtr;
char c = buf[ptr++];
final boolean allowSurrogatePairs = mConfig.allowsSurrogatePairEntities();

// Numeric reference?
if (c == '#') {
Expand All @@ -1194,25 +1195,21 @@ protected int resolveSimpleEntity(boolean checkStd)
value = resolveCharEnt(null, false);
ptr = mInputPtr;
c = buf[ptr - 1];

final boolean isValueHighSurrogate = value >= 0xD800 && value <= 0xDBFF;

// If resolving entity surrogate pairs enabled and if current entity
// is in range of high surrogate value, try to find surrogate pair
if (isValueHighSurrogate && mConfig.allowsSurrogatePairEntities()) {
if (allowSurrogatePairs && value >= 0xD800 && value <= 0xDBFF) {
if (c == ';' && ptr + 1 < inputLen) {
c = buf[ptr++];

if (c == '&' && ptr + 1 < inputLen) {
c = buf[ptr++];

if (c == '#' && ptr + 1 < inputLen) {
try {
mInputPtr = ptr;
pairValue = resolveCharEnt(null, false);
ptr = mInputPtr;
c = buf[ptr -1];
} catch(WstxUnexpectedCharException wuce) {
} catch (WstxUnexpectedCharException wuce) {
reportNoSurrogatePair(value);
}
} else {
Expand All @@ -1230,8 +1227,8 @@ protected int resolveSimpleEntity(boolean checkStd)
// input in current buffer.
if (c == ';') { // got the full thing
mInputPtr = ptr;
if (mConfig.allowsSurrogatePairEntities() && pairValue > 0) {

if (allowSurrogatePairs && pairValue > 0) {
// [woodstox-core#165]
// If pair value is not in range of low surrogate values, then throw an error
if (pairValue < 0xDC00 || pairValue > 0xDFFF) {
Expand Down

0 comments on commit c57023d

Please sign in to comment.