Skip to content

Commit fce75dc

Browse files
committed
Emit no closing tag in SimpleXmlEncoder#resetStream
The `resetStream()` method in the `SimpleXmlEncoder` should not output a closing root tag if no output was generated. See issue #249 for the same issue in `closeStream`.
1 parent 7a5bfa6 commit fce75dc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ public void literal(final String name, final String value) {
176176

177177
@Override
178178
protected void onResetStream() {
179-
writeFooter();
179+
if (!atStreamStart) {
180+
writeFooter();
181+
}
180182
sendAndClearData();
181183
atStreamStart = true;
182184
}

src/test/java/org/culturegraph/mf/stream/converter/xml/SimpleXmlEncoderTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package org.culturegraph.mf.stream.converter.xml;
1717

18-
19-
20-
2118
import static org.junit.Assert.assertEquals;
2219
import static org.junit.Assert.assertTrue;
2320

@@ -55,7 +52,7 @@ public void process(final String obj) {
5552
}
5653
});
5754
resultCollector = new StringBuilder();
58-
}
55+
}
5956

6057
@Test
6158
public void issue249_shouldNotEmitClosingRootTagOnCloseStreamIfNoOutputWasGenerated() {
@@ -64,6 +61,13 @@ public void issue249_shouldNotEmitClosingRootTagOnCloseStreamIfNoOutputWasGenera
6461
assertTrue(getResultXml().isEmpty());
6562
}
6663

64+
@Test
65+
public void shouldNotEmitClosingRootTagOnResetStreamIfNoOutputWasGenerated() {
66+
simpleXmlEncoder.resetStream();
67+
68+
assertTrue(getResultXml().isEmpty());
69+
}
70+
6771
@Test
6872
public void shouldOnlyEscapeXmlReservedCharacters() {
6973
final StringBuilder builder = new StringBuilder();

0 commit comments

Comments
 (0)