Skip to content

Commit

Permalink
Fix #132
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 20, 2021
1 parent b2d6e37 commit 8029523
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.fasterxml</groupId>
<artifactId>oss-parent</artifactId>
<version>41</version>
<version>43</version>
</parent>

<groupId>com.fasterxml.woodstox</groupId>
Expand Down
2 changes: 2 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Daniel Lowe (dan2097@github)

* Reported #97: `copyEventFromReader()` `ArrayIndexOutOfBoundsException`
(6.0.3)
* Reported #132: `copyEventFromReader()` Processing Instruction event bug
(6.0.7)

Konrad Windszus (kwin@github)

Expand Down
4 changes: 3 additions & 1 deletion release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Project: woodstox
=== Releases ===
------------------------------------------------------------------------

Not yet released
6.2.7 (not yet released)

#132: `copyEventFromReader()` Processing Instruction event bug
(reported by Daniel L)
- A few LGTM.com fixes

6.2.6 (19-Apr-2021)
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/ctc/wstx/sw/BaseStreamWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public void copyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData)
writeEndDocument();
return;

// Element start/end events:
// Element start/end events:
case START_ELEMENT:
if (sr instanceof StreamReaderImpl) {
StreamReaderImpl impl = (StreamReaderImpl) sr;
Expand Down Expand Up @@ -875,7 +875,14 @@ public void copyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData)

case PROCESSING_INSTRUCTION:
{
mAnyOutput = true;
// Need to finish an open start element?
if (mStartElementOpen) {
closeStartElement(mEmptyElement);
}
mWriter.writePIStart(sr.getPITarget(), true);
// Similar to COMMENT, contents assumed to have been validated;
// no escaping allowed, so:
sr.getText(wrapAsRawWriter(), preserveEventData);
mWriter.writePIEnd();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ctc/wstx/sw/BufferingXmlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ public void writeStartTagStart(String prefix, String localName)
@Override
public void writeStartTagEnd() throws IOException {
fastWriteRaw('>');
}
}

@Override
public void writeStartTagEmptyEnd() throws IOException
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/ctc/wstx/sw/SimpleNsStreamWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ public final void copyStartElement(InputElementStack elemStack,
}
}

/* And then let's just output attributes, if any (whether to copy
* implicit, aka "default" attributes, is configurable)
*/
// And then let's just output attributes, if any (whether to copy
// implicit, aka "default" attributes, is configurable)
int attrCount = mCfgCopyDefaultAttrs ?
attrCollector.getCount() :
attrCollector.getSpecifiedCount();
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/stax2/wstream/TestCopyEventFromReader132.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package stax2.wstream;

import java.io.*;

import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.stax2.XMLOutputFactory2;
import org.codehaus.stax2.XMLStreamReader2;
import org.codehaus.stax2.XMLStreamWriter2;

public class TestCopyEventFromReader132
extends BaseWriterTest
{
// [woodstox-core#132]
public void testCopyPIEvent() throws Exception {
_testCopyPIEvent(true);
_testCopyPIEvent(false);
}

private void _testCopyPIEvent(boolean preserveContents) throws Exception {
final XMLInputFactory2 xmlIn = getInputFactory();
final XMLOutputFactory2 xmlOut = getOutputFactory();
String xml = "<description><?pi?>foo</description>";

XMLStreamReader2 reader = (XMLStreamReader2) xmlIn.createXMLStreamReader(new StringReader(xml));
StringWriter w = new StringWriter();
XMLStreamWriter2 writer = (XMLStreamWriter2) xmlOut.createXMLStreamWriter(w);
while (reader.hasNext()) {
reader.next();
writer.copyEventFromReader(reader, preserveContents);
}
reader.close();
writer.close();

assertEquals("<description><?pi ?>foo</description>", w.toString().trim());
}
}

0 comments on commit 8029523

Please sign in to comment.