summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/parser/ParserScope.cpp4
-rw-r--r--src/core/parser/stack/DocumentHandler.cpp1
-rw-r--r--test/formats/osxml/OsxmlParserTest.cpp17
-rw-r--r--testdata/osxmlparser/empty_named_field.osxml14
4 files changed, 33 insertions, 3 deletions
diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp
index c46dc51..e5bf6f6 100644
--- a/src/core/parser/ParserScope.cpp
+++ b/src/core/parser/ParserScope.cpp
@@ -174,12 +174,12 @@ ParserScope::ParserScope() : topLevelDepth(0) {}
bool ParserScope::checkUnwound(Logger &logger) const
{
- if (nodes.size() != topLevelDepth) {
+ if (nodes.size() > topLevelDepth) {
logger.error("Not all open elements have been closed!",
SourceLocation{}, MessageMode::NO_CONTEXT);
logger.note("Still open elements are: ", SourceLocation{},
MessageMode::NO_CONTEXT);
- for (size_t i = topLevelDepth + 1; i < nodes.size(); i++) {
+ for (size_t i = topLevelDepth; i < nodes.size(); i++) {
logger.note(std::string("Element of interal type ") +
nodes[i]->type()->name +
std::string(" defined here:"),
diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp
index 3e85f72..ce6267f 100644
--- a/src/core/parser/stack/DocumentHandler.cpp
+++ b/src/core/parser/stack/DocumentHandler.cpp
@@ -334,7 +334,6 @@ bool DocumentChildHandler::startCommand(Variant::mapType &args)
}
// Otherwise create a new StructuredEntity
- // TODO: Consider Anchors and AnnotationEntities
Rooted<StructuredClass> strct = scope().resolve<StructuredClass>(
Utils::split(name(), ':'), logger());
if (strct == nullptr) {
diff --git a/test/formats/osxml/OsxmlParserTest.cpp b/test/formats/osxml/OsxmlParserTest.cpp
index 603d6c1..7c7f2a8 100644
--- a/test/formats/osxml/OsxmlParserTest.cpp
+++ b/test/formats/osxml/OsxmlParserTest.cpp
@@ -384,5 +384,22 @@ TEST(OsxmlParser, documentParsing)
}
}
+TEST(OsxmlParser, emptyNamedField){
+ logger.reset();
+ XmlStandaloneEnvironment env(logger);
+ Rooted<Node> book_document_node =
+ env.parse("empty_named_field.osxml", "", "", RttiSet{&RttiTypes::Document});
+ ASSERT_FALSE(logger.hasError());
+ ASSERT_FALSE(book_document_node == nullptr);
+ ASSERT_TRUE(book_document_node->isa(&RttiTypes::Document));
+ // check the document content.
+ Rooted<Document> doc = book_document_node.cast<Document>();
+ ASSERT_TRUE(doc->validate(logger));
+ checkStructuredEntity(doc->getRoot(), doc, doc, "a");
+ ASSERT_EQ(2U, doc->getRoot()->getDescriptor()->getFieldDescriptors().size());
+ ASSERT_TRUE(doc->getRoot()->getField(0).empty());
+ ASSERT_TRUE(doc->getRoot()->getField(1).empty());
+}
+
}
diff --git a/testdata/osxmlparser/empty_named_field.osxml b/testdata/osxmlparser/empty_named_field.osxml
new file mode 100644
index 0000000..2f465ba
--- /dev/null
+++ b/testdata/osxmlparser/empty_named_field.osxml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document>
+ <ontology name="test">
+ <struct name="a" root="true">
+ <field name="afield" subtree="true">
+ <childRef ref="a"/>
+ </field>
+ </struct>
+ </ontology>
+
+ <a>
+ <afield/>
+ </a>
+</document>