fix(serialize-xml): Actually consume header
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2024-04-20 22:15:37 +02:00
parent 12d345ca20
commit ca746c05a4
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 17 additions and 0 deletions

View File

@ -271,6 +271,9 @@ public class NativeXmlReader implements Closeable {
} else if (peekStack == XmlScope.TAG_BODY) {
// fall through: a new element is starting
} else if (peekStack == XmlScope.EMPTY_DOCUMENT) {
if (lenient) {
consumeHeader();
}
stack[stackSize - 1] = XmlScope.NONEMPTY_DOCUMENT;
// fall through: a new element is starting
} else if (peekStack == XmlScope.NONEMPTY_DOCUMENT) {
@ -809,6 +812,7 @@ public class NativeXmlReader implements Closeable {
// we found a header, consume it
pos += 5;
skipTo("?>");
pos += 2;
}
@Override

View File

@ -219,6 +219,19 @@ public final class NativeXmlReaderTest {
}
@Test
public void testXmlHeader() throws IOException {
NativeXmlReader reader = new NativeXmlReader(reader("<?xml version=\"1.0\" encoding=\"UTF-8\"?><tag>content</tag>"));
assertThrows(IOException.class, reader::peek);
reader = new NativeXmlReader(reader("<?xml version=\"1.0\" encoding=\"UTF-8\"?><tag>content</tag>"));
reader.setLenient(true);
assertThat(reader.peek()).isEqualTo(XmlToken.BEGIN_TAG);
assertThat(reader.beginTag()).isEqualTo("tag");
assertThat(reader.nextText()).isEqualTo("content");
assertThat(reader.endTag()).isEqualTo("tag");
assertThat(reader.peek()).isEqualTo(XmlToken.EOF);
}
// @Test
// public void testHelloWorld() throws IOException {
// String json =