Skip to content

Commit ae2acc2

Browse files
committed
Fix entity buffer cache. Closes #7.
1 parent 7f409ec commit ae2acc2

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</properties>
88
<body>
99
<release version="1.2.3-SNAPSHOT" date="yyyy-MM-dd" description="Maintenance version">
10+
<action dev="joehni" type="fix" issue="7">Fix entity parser cache..</action>
1011
<action dev="joehni" type="add">Add KEYS file with public keys to verify signed artifacts.</action>
1112
</release>
1213
<release version="1.2.2" date="2021-08-19" description="Maintenance version">

src/main/java/io/github/xstream/mxparser/MXParser.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private void ensureEntityCapacity() {
375375
private Boolean xmlDeclStandalone;
376376
private String xmlDeclContent;
377377

378-
private static boolean noUnicode4;
378+
private static boolean noUnicode4; // no Unicode in Java 1.4
379379

380380
private void reset() {
381381
//System.out.println("reset() called");
@@ -2153,7 +2153,7 @@ else if(xmlnsPos == 5) {
21532153
return ch;
21542154
}
21552155

2156-
private char[] charRefOneCharBuf = new char[1];
2156+
final private char[] charRefOneCharBuf = new char[1];
21572157

21582158
private char[] parseEntityRef()
21592159
throws XmlPullParserException, IOException
@@ -2209,9 +2209,10 @@ private char[] parseEntityRef()
22092209
}
22102210
}
22112211
posEnd = pos - 1;
2212+
char[] result = null;
22122213
if (!noUnicode4) {
22132214
try {
2214-
charRefOneCharBuf = Character.toChars(Integer.parseInt(sb.toString(), isHex ? 16 : 10));
2215+
result = Character.toChars(Integer.parseInt(sb.toString(), isHex ? 16 : 10));
22152216
} catch (IllegalArgumentException e) {
22162217
throw new XmlPullParserException("character reference (with "
22172218
+ (isHex ? "hex" : "decimal")
@@ -2231,13 +2232,13 @@ private char[] parseEntityRef()
22312232
+ sb.toString()
22322233
+ ") is not supported in this runtime", this, null);
22332234
}
2234-
charRefOneCharBuf = new char[1];
2235+
result = charRefOneCharBuf;
22352236
charRefOneCharBuf[0] = (char)i;
22362237
}
22372238
if(tokenize) {
2238-
text = newString(charRefOneCharBuf, 0, charRefOneCharBuf.length);
2239+
text = newString(result, 0, result.length);
22392240
}
2240-
return charRefOneCharBuf;
2241+
return result;
22412242
} else {
22422243
// [68] EntityRef ::= '&' Name ';'
22432244
// scan name until ;

src/test/java/io/github/xstream/mxparser/MXParserTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
/**
3232
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
33-
*
3433
*/
3534
public class MXParserTest
3635
{
@@ -255,6 +254,27 @@ public void testValidCharacterReferenceDecimal()
255254
}
256255
}
257256

257+
@Test
258+
public void testAmpersandAfterSupplementaryCharacter()
259+
throws Exception
260+
{
261+
MXParser parser = new MXParser();
262+
String input = "<root>&amp; before, supplementary symbol &#1113101;, &amp; after</root>";
263+
parser.setInput( new StringReader( input ) );
264+
265+
try
266+
{
267+
assertEquals( XmlPullParser.START_TAG, parser.nextToken() );
268+
assertEquals( XmlPullParser.TEXT, parser.next() );
269+
assertEquals( "& before, supplementary symbol \uDBFF\uDC0D, & after", parser.getText() );
270+
assertEquals( XmlPullParser.END_TAG, parser.nextToken() );
271+
}
272+
catch ( XmlPullParserException e )
273+
{
274+
fail( "Should success since the input represents all legal character references" );
275+
}
276+
}
277+
258278
@Test
259279
public void testValidCDATA()
260280
throws Exception

0 commit comments

Comments
 (0)