Skip to content

Commit ddeb949

Browse files
committed
Fix #78
1 parent f5607db commit ddeb949

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.fasterxml</groupId>
66
<artifactId>oss-parent</artifactId>
7-
<version>41</version>
7+
<version>44</version>
88
</parent>
99

1010
<artifactId>aalto-xml</artifactId>

release-notes/CREDITS

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ Claude Mamo (otcdlink-simpleuser@github)
3333
Erik Fäßler (khituras@github)
3434
* Contributed #75: Fixing a bug when multi-byte characters were split
3535
(1.3.1)
36+
37+
Jamie Phelps (jphelp32@github)
38+
* Reported #78: Async parsing turns &quot; inside element content into apostrophe
39+
(1.3.2)

release-notes/VERSION

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: aalto-xml
44
= Releases
55
------------------------------------------------------------------------
66

7+
1.3.2 (not yet released)
8+
9+
#78: Async parsing turns &quot; inside element content into apostrophe
10+
(reported by Jamie P)
11+
712
1.3.1 (14-Jan-2022)
813

914
#75: Fixing a bug when multi-byte characters were split

src/main/java/com/fasterxml/aalto/async/AsyncByteArrayScanner.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ protected int handleEntityInCharacters() throws XMLStreamException
23932393
&& _inputBuffer[ptr+2] == BYTE_t
23942394
&& _inputBuffer[ptr+3] == BYTE_SEMICOLON) {
23952395
_inputPtr = ptr + 4;
2396-
return INT_APOS;
2396+
return INT_QUOTE;
23972397
}
23982398
}
23992399
}
@@ -2949,7 +2949,7 @@ private int skipEntityInCharacters() throws XMLStreamException
29492949
&& _inputBuffer[ptr+2] == BYTE_t
29502950
&& _inputBuffer[ptr+3] == BYTE_SEMICOLON) {
29512951
_inputPtr = ptr + 4;
2952-
return INT_APOS;
2952+
return INT_QUOTE;
29532953
}
29542954
}
29552955
}

src/main/java/com/fasterxml/aalto/async/AsyncByteBufferScanner.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,7 @@ protected int handleEntityInCharacters() throws XMLStreamException
23982398
&& _inputBuffer.get(ptr+2) == BYTE_t
23992399
&& _inputBuffer.get(ptr+3) == BYTE_SEMICOLON) {
24002400
_inputPtr = ptr + 4;
2401-
return INT_APOS;
2401+
return INT_QUOTE;
24022402
}
24032403
}
24042404
}
@@ -2954,7 +2954,7 @@ private int skipEntityInCharacters() throws XMLStreamException
29542954
&& _inputBuffer.get(ptr+2) == BYTE_t
29552955
&& _inputBuffer.get(ptr+3) == BYTE_SEMICOLON) {
29562956
_inputPtr = ptr + 4;
2957-
return INT_APOS;
2957+
return INT_QUOTE;
29582958
}
29592959
}
29602960
}

src/main/java/com/fasterxml/aalto/async/AsyncByteScanner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public void endOfInput() {
372372
protected void _releaseBuffers()
373373
{
374374
super._releaseBuffers();
375-
if (_symbols.maybeDirty()) {
375+
if ((_symbols != null) && _symbols.maybeDirty()) {
376376
_config.updateBBSymbols(_symbols);
377377
}
378378
}

src/test/java/async/TestCharactersParsing.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@ private void _testLinefeeds(final AsyncXMLStreamReader<?> sr, final AsyncReaderW
141141

142142
private void _testTextWithEntities(final int chunkSize, final boolean checkValues, final String SPC) throws Exception
143143
{
144-
final String XML = SPC + "<root>a&lt;b\rMOT</root>";
144+
_testTextWithEntities(chunkSize, checkValues, SPC, "&lt", "<");
145+
_testTextWithEntities(chunkSize, checkValues, SPC, "&gt", ">");
146+
_testTextWithEntities(chunkSize, checkValues, SPC, "&apos", "'");
147+
// for [aalto-xml#78]
148+
_testTextWithEntities(chunkSize, checkValues, SPC, "&quot", "\"");
149+
}
150+
151+
private void _testTextWithEntities(final int chunkSize, final boolean checkValues, final String SPC,
152+
final String entity, final String entityExpanded) throws Exception
153+
{
154+
final String XML = SPC + "<root>a"+entity+";b\rMOT</root>";
145155

146156
final AsyncXMLInputFactory f = new InputFactoryImpl();
147157

@@ -150,7 +160,7 @@ private void _testTextWithEntities(final int chunkSize, final boolean checkValue
150160
try {
151161
sr_array = f.createAsyncForByteArray();
152162
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
153-
_testTextWithEntities(sr_array, reader_array, checkValues);
163+
_testTextWithEntities(sr_array, reader_array, checkValues, entityExpanded);
154164
} finally {
155165
if (sr_array != null) {
156166
sr_array.close();
@@ -162,15 +172,17 @@ private void _testTextWithEntities(final int chunkSize, final boolean checkValue
162172
try {
163173
sr_buffer = f.createAsyncForByteBuffer();
164174
final AsyncReaderWrapperForByteBuffer reader_buffer = new AsyncReaderWrapperForByteBuffer(sr_buffer, chunkSize, XML);
165-
_testTextWithEntities(sr_buffer, reader_buffer, checkValues);
175+
_testTextWithEntities(sr_buffer, reader_buffer, checkValues, entityExpanded);
166176
} finally {
167177
if (sr_buffer != null) {
168178
sr_buffer.close();
169179
}
170180
}
171181
}
172182

173-
private void _testTextWithEntities(final AsyncXMLStreamReader<?> sr, final AsyncReaderWrapper reader, final boolean checkValues) throws Exception
183+
private void _testTextWithEntities(final AsyncXMLStreamReader<?> sr, final AsyncReaderWrapper reader,
184+
final boolean checkValues,
185+
final String entityExpanded) throws Exception
174186
{
175187
// should start with START_DOCUMENT, but for now skip
176188
int t = verifyStart(reader);
@@ -182,7 +194,7 @@ private void _testTextWithEntities(final AsyncXMLStreamReader<?> sr, final Async
182194
assertTokenType(CHARACTERS, reader.nextToken());
183195
if (checkValues) {
184196
String str = collectAsyncText(reader, CHARACTERS); // moves to end-element
185-
assertEquals("a<b\nMOT", str);
197+
assertEquals("a"+entityExpanded+"b\nMOT", str);
186198
} else {
187199
reader.nextToken();
188200
}

0 commit comments

Comments
 (0)