From 8992e423932a276ac43ea0a4aaac3bd164cb5e95 Mon Sep 17 00:00:00 2001 From: JFronny Date: Sat, 20 Apr 2024 16:42:39 +0200 Subject: [PATCH] fix(serialize-xml): prevent overzealous null --- .../commons/serialize/xml/NativeXmlReader.java | 14 ++++++++++++++ .../commons/serialize/xml/wrapper/XmlReader.java | 1 + 2 files changed, 15 insertions(+) diff --git a/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/NativeXmlReader.java b/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/NativeXmlReader.java index b654550..3f4c6e9 100644 --- a/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/NativeXmlReader.java +++ b/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/NativeXmlReader.java @@ -190,6 +190,20 @@ public class NativeXmlReader implements Closeable { return p != PEEKED_EOF && p != PEEKED_END_TAG && p != PEEKED_END_TAG_CONCISE; } + public boolean isConciseEndTag() throws IOException { + int p = peeked; + if (p == PEEKED_NONE) { + p = doPeek(); + } + if (p == PEEKED_END_TAG_CONCISE) { + return true; + } else if (p == PEEKED_END_TAG) { + return false; + } else { + throw unexpectedTokenError("END_TAG"); + } + } + public XmlToken peek() throws IOException { int p = peeked; if (p == PEEKED_NONE) { diff --git a/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/wrapper/XmlReader.java b/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/wrapper/XmlReader.java index 46b3f29..248acd8 100644 --- a/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/wrapper/XmlReader.java +++ b/commons-serialize-xml/src/main/java/io/gitlab/jfronny/commons/serialize/xml/wrapper/XmlReader.java @@ -263,6 +263,7 @@ public class XmlReader extends SerializeReader implement yield doPeek(); } case WrapperScope.OBJECT_VALUE_WRAPPER -> { + if (!reader.isConciseEndTag()) throw syntaxError("Unexpected end tag"); stackSize--; reader.endTag(); yield PEEKED_NULL_VIRTUAL;