From ddeb949017a2832448d7adae56c9bff3af4a96b5 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 24 Apr 2022 18:42:22 -0700 Subject: [PATCH] Fix #78 --- pom.xml | 2 +- release-notes/CREDITS | 4 ++++ release-notes/VERSION | 5 +++++ .../aalto/async/AsyncByteArrayScanner.java | 4 ++-- .../aalto/async/AsyncByteBufferScanner.java | 4 ++-- .../aalto/async/AsyncByteScanner.java | 2 +- .../java/async/TestCharactersParsing.java | 22 ++++++++++++++----- 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 972f593..e895b64 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.fasterxml oss-parent - 41 + 44 aalto-xml diff --git a/release-notes/CREDITS b/release-notes/CREDITS index 0d5b189..ac2570d 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -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 " inside element content into apostrophe + (1.3.2) diff --git a/release-notes/VERSION b/release-notes/VERSION index c325e76..3db5f1f 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -4,6 +4,11 @@ Project: aalto-xml = Releases ------------------------------------------------------------------------ +1.3.2 (not yet released) + +#78: Async parsing turns " 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 diff --git a/src/main/java/com/fasterxml/aalto/async/AsyncByteArrayScanner.java b/src/main/java/com/fasterxml/aalto/async/AsyncByteArrayScanner.java index 6d21357..f66b894 100644 --- a/src/main/java/com/fasterxml/aalto/async/AsyncByteArrayScanner.java +++ b/src/main/java/com/fasterxml/aalto/async/AsyncByteArrayScanner.java @@ -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; } } } @@ -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; } } } diff --git a/src/main/java/com/fasterxml/aalto/async/AsyncByteBufferScanner.java b/src/main/java/com/fasterxml/aalto/async/AsyncByteBufferScanner.java index 7047b34..135135a 100644 --- a/src/main/java/com/fasterxml/aalto/async/AsyncByteBufferScanner.java +++ b/src/main/java/com/fasterxml/aalto/async/AsyncByteBufferScanner.java @@ -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; } } } @@ -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; } } } diff --git a/src/main/java/com/fasterxml/aalto/async/AsyncByteScanner.java b/src/main/java/com/fasterxml/aalto/async/AsyncByteScanner.java index 642b4a5..74a3ab8 100644 --- a/src/main/java/com/fasterxml/aalto/async/AsyncByteScanner.java +++ b/src/main/java/com/fasterxml/aalto/async/AsyncByteScanner.java @@ -372,7 +372,7 @@ public void endOfInput() { protected void _releaseBuffers() { super._releaseBuffers(); - if (_symbols.maybeDirty()) { + if ((_symbols != null) && _symbols.maybeDirty()) { _config.updateBBSymbols(_symbols); } } diff --git a/src/test/java/async/TestCharactersParsing.java b/src/test/java/async/TestCharactersParsing.java index 8aa43e2..29df3ad 100644 --- a/src/test/java/async/TestCharactersParsing.java +++ b/src/test/java/async/TestCharactersParsing.java @@ -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 + "a<b\rMOT"; + _testTextWithEntities(chunkSize, checkValues, SPC, "<", "<"); + _testTextWithEntities(chunkSize, checkValues, SPC, ">", ">"); + _testTextWithEntities(chunkSize, checkValues, SPC, "&apos", "'"); + // for [aalto-xml#78] + _testTextWithEntities(chunkSize, checkValues, SPC, """, "\""); + } + + private void _testTextWithEntities(final int chunkSize, final boolean checkValues, final String SPC, + final String entity, final String entityExpanded) throws Exception + { + final String XML = SPC + "a"+entity+";b\rMOT"; final AsyncXMLInputFactory f = new InputFactoryImpl(); @@ -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(); @@ -162,7 +172,7 @@ 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(); @@ -170,7 +180,9 @@ private void _testTextWithEntities(final int chunkSize, final boolean checkValue } } - 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); @@ -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