Skip to content

Commit

Permalink
Fix #78
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 25, 2022
1 parent f5607db commit ddeb949
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.fasterxml</groupId>
<artifactId>oss-parent</artifactId>
<version>41</version>
<version>44</version>
</parent>

<artifactId>aalto-xml</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Expand Up @@ -33,3 +33,7 @@ Claude Mamo (otcdlink-simpleuser@github)
Erik Fäßler (khituras@github)
* Contributed #75: Fixing a bug when multi-byte characters were split
(1.3.1)

Jamie Phelps (jphelp32@github)
* Reported #78: Async parsing turns &quot; inside element content into apostrophe
(1.3.2)
5 changes: 5 additions & 0 deletions release-notes/VERSION
Expand Up @@ -4,6 +4,11 @@ Project: aalto-xml
= Releases
------------------------------------------------------------------------

1.3.2 (not yet released)

#78: Async parsing turns &quot; inside element content into apostrophe
(reported by Jamie P)

1.3.1 (14-Jan-2022)

#75: Fixing a bug when multi-byte characters were split
Expand Down
Expand Up @@ -2393,7 +2393,7 @@ protected int handleEntityInCharacters() throws XMLStreamException
&& _inputBuffer[ptr+2] == BYTE_t
&& _inputBuffer[ptr+3] == BYTE_SEMICOLON) {
_inputPtr = ptr + 4;
return INT_APOS;
return INT_QUOTE;
}
}
}
Expand Down Expand Up @@ -2949,7 +2949,7 @@ private int skipEntityInCharacters() throws XMLStreamException
&& _inputBuffer[ptr+2] == BYTE_t
&& _inputBuffer[ptr+3] == BYTE_SEMICOLON) {
_inputPtr = ptr + 4;
return INT_APOS;
return INT_QUOTE;
}
}
}
Expand Down
Expand Up @@ -2398,7 +2398,7 @@ protected int handleEntityInCharacters() throws XMLStreamException
&& _inputBuffer.get(ptr+2) == BYTE_t
&& _inputBuffer.get(ptr+3) == BYTE_SEMICOLON) {
_inputPtr = ptr + 4;
return INT_APOS;
return INT_QUOTE;
}
}
}
Expand Down Expand Up @@ -2954,7 +2954,7 @@ private int skipEntityInCharacters() throws XMLStreamException
&& _inputBuffer.get(ptr+2) == BYTE_t
&& _inputBuffer.get(ptr+3) == BYTE_SEMICOLON) {
_inputPtr = ptr + 4;
return INT_APOS;
return INT_QUOTE;
}
}
}
Expand Down
Expand Up @@ -372,7 +372,7 @@ public void endOfInput() {
protected void _releaseBuffers()
{
super._releaseBuffers();
if (_symbols.maybeDirty()) {
if ((_symbols != null) && _symbols.maybeDirty()) {
_config.updateBBSymbols(_symbols);
}
}
Expand Down
22 changes: 17 additions & 5 deletions src/test/java/async/TestCharactersParsing.java
Expand Up @@ -141,7 +141,17 @@ private void _testLinefeeds(final AsyncXMLStreamReader<?> sr, final AsyncReaderW

private void _testTextWithEntities(final int chunkSize, final boolean checkValues, final String SPC) throws Exception
{
final String XML = SPC + "<root>a&lt;b\rMOT</root>";
_testTextWithEntities(chunkSize, checkValues, SPC, "&lt", "<");
_testTextWithEntities(chunkSize, checkValues, SPC, "&gt", ">");
_testTextWithEntities(chunkSize, checkValues, SPC, "&apos", "'");
// for [aalto-xml#78]
_testTextWithEntities(chunkSize, checkValues, SPC, "&quot", "\"");
}

private void _testTextWithEntities(final int chunkSize, final boolean checkValues, final String SPC,
final String entity, final String entityExpanded) throws Exception
{
final String XML = SPC + "<root>a"+entity+";b\rMOT</root>";

final AsyncXMLInputFactory f = new InputFactoryImpl();

Expand All @@ -150,7 +160,7 @@ private void _testTextWithEntities(final int chunkSize, final boolean checkValue
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testTextWithEntities(sr_array, reader_array, checkValues);
_testTextWithEntities(sr_array, reader_array, checkValues, entityExpanded);
} finally {
if (sr_array != null) {
sr_array.close();
Expand All @@ -162,15 +172,17 @@ private void _testTextWithEntities(final int chunkSize, final boolean checkValue
try {
sr_buffer = f.createAsyncForByteBuffer();
final AsyncReaderWrapperForByteBuffer reader_buffer = new AsyncReaderWrapperForByteBuffer(sr_buffer, chunkSize, XML);
_testTextWithEntities(sr_buffer, reader_buffer, checkValues);
_testTextWithEntities(sr_buffer, reader_buffer, checkValues, entityExpanded);
} finally {
if (sr_buffer != null) {
sr_buffer.close();
}
}
}

private void _testTextWithEntities(final AsyncXMLStreamReader<?> sr, final AsyncReaderWrapper reader, final boolean checkValues) throws Exception
private void _testTextWithEntities(final AsyncXMLStreamReader<?> sr, final AsyncReaderWrapper reader,
final boolean checkValues,
final String entityExpanded) throws Exception
{
// should start with START_DOCUMENT, but for now skip
int t = verifyStart(reader);
Expand All @@ -182,7 +194,7 @@ private void _testTextWithEntities(final AsyncXMLStreamReader<?> sr, final Async
assertTokenType(CHARACTERS, reader.nextToken());
if (checkValues) {
String str = collectAsyncText(reader, CHARACTERS); // moves to end-element
assertEquals("a<b\nMOT", str);
assertEquals("a"+entityExpanded+"b\nMOT", str);
} else {
reader.nextToken();
}
Expand Down

0 comments on commit ddeb949

Please sign in to comment.