From 4a256472344435d4fd6954298753b7fea68d1f44 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 22 Mar 2024 13:03:03 -0700 Subject: [PATCH 1/2] Update oss-parent ref --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf5a14f..253f6c0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.fasterxml oss-parent - 56 + 58 com.fasterxml.woodstox From ef10fdca71b298d3a20bdb7434e68e0e798a6812 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 22 Mar 2024 13:03:52 -0700 Subject: [PATCH 2/2] Fix indentation of test class (remove tabs) --- .../wstxtest/wstream/TestInvalidChars.java | 237 +++++++++--------- 1 file changed, 115 insertions(+), 122 deletions(-) diff --git a/src/test/java/wstxtest/wstream/TestInvalidChars.java b/src/test/java/wstxtest/wstream/TestInvalidChars.java index 2fadd4e..f19cf9b 100644 --- a/src/test/java/wstxtest/wstream/TestInvalidChars.java +++ b/src/test/java/wstxtest/wstream/TestInvalidChars.java @@ -26,50 +26,54 @@ public class TestInvalidChars public void testInvalidCatchingCharacters() throws XMLStreamException { - doTestInvalid(CHARACTERS); + doTestInvalid(CHARACTERS); } public void testInvalidCatchingCData() throws XMLStreamException { - doTestInvalid(CDATA); + doTestInvalid(CDATA); } + public void testInvalidCatchingComment() throws XMLStreamException { - doTestInvalid(COMMENT); + doTestInvalid(COMMENT); } + public void testInvalidCatchingPI() throws XMLStreamException { - doTestInvalid(PROCESSING_INSTRUCTION); + doTestInvalid(PROCESSING_INSTRUCTION); } public void testInvalidCatchingAttribute() throws XMLStreamException { - doTestInvalid(ATTRIBUTE); + doTestInvalid(ATTRIBUTE); } // // And then also that we can fix problems public void testValidReplacingCharacters() throws Exception { - doTestValid(CHARACTERS); + doTestValid(CHARACTERS); } public void testValidReplacingCData() throws Exception { - doTestValid(CDATA); + doTestValid(CDATA); } + public void testValidReplacingComment() throws Exception { - doTestValid(COMMENT); + doTestValid(COMMENT); } + public void testValidReplacingPI() throws Exception { - doTestValid(PROCESSING_INSTRUCTION); + doTestValid(PROCESSING_INSTRUCTION); } public void testValidReplacingAttribute() throws Exception { - doTestValid(ATTRIBUTE); + doTestValid(ATTRIBUTE); } /* @@ -79,124 +83,116 @@ public void testValidReplacingAttribute() throws Exception */ private void doTestInvalid(int evtType) - throws XMLStreamException + throws XMLStreamException { XMLOutputFactory2 f = getFactory(null); - doTestInvalid(evtType, f.createXMLStreamWriter(new ByteArrayOutputStream(), "ISO-8859-1"), true); - doTestInvalid(evtType, f.createXMLStreamWriter(new ByteArrayOutputStream(), "US-ASCII"), true); - // [WSTX-173] affects backends that do not do their own encoding: - doTestInvalid(evtType, f.createXMLStreamWriter(new StringWriter()), false); - doTestInvalid(evtType, f.createXMLStreamWriter(new ByteArrayOutputStream(), "UTF-8"), false); + doTestInvalid(evtType, f.createXMLStreamWriter(new ByteArrayOutputStream(), "ISO-8859-1"), true); + doTestInvalid(evtType, f.createXMLStreamWriter(new ByteArrayOutputStream(), "US-ASCII"), true); + // [WSTX-173] affects backends that do not do their own encoding: + doTestInvalid(evtType, f.createXMLStreamWriter(new StringWriter()), false); + doTestInvalid(evtType, f.createXMLStreamWriter(new ByteArrayOutputStream(), "UTF-8"), false); } /** - * @param strictChecks Due to [WSTX-173], may need to relax some checks - * to pass for now. Not needed once bug is fixed. + * @param strictChecks Due to [WSTX-173], may need to relax some checks to pass + * for now. Not needed once bug is fixed. */ - private void doTestInvalid(int evtType, XMLStreamWriter sw1, - boolean strictChecks) - throws XMLStreamException - { - XMLStreamWriter2 sw = (XMLStreamWriter2) sw1; - sw.writeStartDocument(); - sw.writeStartElement("root"); - try { - switch (evtType) { - case ATTRIBUTE: - sw.writeAttribute("attr", INVALID_TEXT); - // always strict for attributes and characters - handleFailure(sw, "Expected an exception for ATTRIBUTE", true); - break; - case CHARACTERS: - sw.writeCharacters(INVALID_TEXT); - handleFailure(sw, "Expected an exception for CHARACTERS", true); - break; - case CDATA: - sw.writeCData(INVALID_TEXT); - handleFailure(sw, "Expected an exception for CDATA", strictChecks); - break; - case COMMENT: - sw.writeComment(INVALID_TEXT); - handleFailure(sw, "Expected an exception for COMMENT", strictChecks); - break; - case PROCESSING_INSTRUCTION: - sw.writeProcessingInstruction("pi", INVALID_TEXT); - handleFailure(sw, "Expected an exception for PROCESSING_INSTRUCTION", strictChecks); - break; - } - } catch (XMLStreamException xse) { - sw.closeCompletely(); - } - } - - private void doTestValid(int evtType) - throws IOException, XMLStreamException - { + private void doTestInvalid(int evtType, XMLStreamWriter sw1, boolean strictChecks) throws XMLStreamException { + XMLStreamWriter2 sw = (XMLStreamWriter2) sw1; + sw.writeStartDocument(); + sw.writeStartElement("root"); + try { + switch (evtType) { + case ATTRIBUTE: + sw.writeAttribute("attr", INVALID_TEXT); + // always strict for attributes and characters + handleFailure(sw, "Expected an exception for ATTRIBUTE", true); + break; + case CHARACTERS: + sw.writeCharacters(INVALID_TEXT); + handleFailure(sw, "Expected an exception for CHARACTERS", true); + break; + case CDATA: + sw.writeCData(INVALID_TEXT); + handleFailure(sw, "Expected an exception for CDATA", strictChecks); + break; + case COMMENT: + sw.writeComment(INVALID_TEXT); + handleFailure(sw, "Expected an exception for COMMENT", strictChecks); + break; + case PROCESSING_INSTRUCTION: + sw.writeProcessingInstruction("pi", INVALID_TEXT); + handleFailure(sw, "Expected an exception for PROCESSING_INSTRUCTION", strictChecks); + break; + } + } catch (XMLStreamException xse) { + sw.closeCompletely(); + } + } + + private void doTestValid(int evtType) throws IOException, XMLStreamException { XMLOutputFactory2 f = getFactory(REPL_CHAR); - doTestValid(f, evtType, "ISO-8859-1", true); - doTestValid(f, evtType, "US-ASCII", true); + doTestValid(f, evtType, "ISO-8859-1", true); + doTestValid(f, evtType, "US-ASCII", true); - // [WSTX-173] affects backends that do not do their own encoding: - doTestValid(f, evtType, "UTF-8", false); + // [WSTX-173] affects backends that do not do their own encoding: + doTestValid(f, evtType, "UTF-8", false); - StringWriter strw = new StringWriter(); - XMLStreamWriter sw = f.createXMLStreamWriter(strw); - buildValid(evtType, sw); - verifyValidReplacement(evtType, sw, strw.toString(), false); + StringWriter strw = new StringWriter(); + XMLStreamWriter sw = f.createXMLStreamWriter(strw); + buildValid(evtType, sw); + verifyValidReplacement(evtType, sw, strw.toString(), false); } private void doTestValid(XMLOutputFactory2 f, int evtType, String enc, boolean strict) - throws IOException, XMLStreamException - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - XMLStreamWriter sw = f.createXMLStreamWriter(out, enc); - buildValid(evtType, sw); - verifyValidReplacement(evtType, sw, out.toString(enc), strict); - } - - private void verifyValidReplacement(int evtType, XMLStreamWriter sw, String doc, boolean strict) - { - if (doc.indexOf(REPL_CHAR.charValue()) < 0) { // no replacement... - handleFailure(sw, "Failed to replace invalid char, event "+tokenTypeDesc(evtType)+", xml = '"+doc+"'", strict); - } - } - - private void buildValid(int evtType, XMLStreamWriter sw1) - throws XMLStreamException - { - XMLStreamWriter2 sw = (XMLStreamWriter2) sw1; - sw.writeStartDocument(); - sw.writeStartElement("root"); - - switch (evtType) { - case ATTRIBUTE: - sw.writeAttribute("attr", INVALID_TEXT); - break; - case CHARACTERS: - sw.writeCharacters(INVALID_TEXT); - break; - case CDATA: - sw.writeCData(INVALID_TEXT); - break; - case COMMENT: - sw.writeComment(INVALID_TEXT); - break; - case PROCESSING_INSTRUCTION: - sw.writeProcessingInstruction("pi", INVALID_TEXT); - break; - } - sw.writeEndElement(); - sw.writeEndDocument(); - sw.closeCompletely(); - } - - private void handleFailure(XMLStreamWriter sw, String msg, boolean doFail) - { - if (doFail) { - fail(msg+" (stream writer: "+sw+")"); - } else { - warn("suppressing failure '"+msg+"' (stream writer: "+sw+")"); - } + throws IOException, XMLStreamException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + XMLStreamWriter sw = f.createXMLStreamWriter(out, enc); + buildValid(evtType, sw); + verifyValidReplacement(evtType, sw, out.toString(enc), strict); + } + + private void verifyValidReplacement(int evtType, XMLStreamWriter sw, String doc, boolean strict) { + if (doc.indexOf(REPL_CHAR.charValue()) < 0) { // no replacement... + handleFailure(sw, + "Failed to replace invalid char, event " + tokenTypeDesc(evtType) + ", xml = '" + doc + "'", + strict); + } + } + + private void buildValid(int evtType, XMLStreamWriter sw1) throws XMLStreamException { + XMLStreamWriter2 sw = (XMLStreamWriter2) sw1; + sw.writeStartDocument(); + sw.writeStartElement("root"); + + switch (evtType) { + case ATTRIBUTE: + sw.writeAttribute("attr", INVALID_TEXT); + break; + case CHARACTERS: + sw.writeCharacters(INVALID_TEXT); + break; + case CDATA: + sw.writeCData(INVALID_TEXT); + break; + case COMMENT: + sw.writeComment(INVALID_TEXT); + break; + case PROCESSING_INSTRUCTION: + sw.writeProcessingInstruction("pi", INVALID_TEXT); + break; + } + sw.writeEndElement(); + sw.writeEndDocument(); + sw.closeCompletely(); + } + + private void handleFailure(XMLStreamWriter sw, String msg, boolean doFail) { + if (doFail) { + fail(msg + " (stream writer: " + sw + ")"); + } else { + warn("suppressing failure '" + msg + "' (stream writer: " + sw + ")"); + } } /* @@ -205,15 +201,12 @@ private void handleFailure(XMLStreamWriter sw, String msg, boolean doFail) ////////////////////////////////////////////// */ - private XMLOutputFactory2 getFactory(Character replChar) - throws XMLStreamException - { + private XMLOutputFactory2 getFactory(Character replChar) throws XMLStreamException { XMLOutputFactory2 f = getOutputFactory(); setRepairing(f, false); setValidateContent(f, true); - f.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER, - (replChar == null) ? null : new InvalidCharHandler.ReplacingHandler(replChar.charValue())); + f.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER, + (replChar == null) ? null : new InvalidCharHandler.ReplacingHandler(replChar.charValue())); return f; } } -