summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-12-10 03:02:04 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-12-10 03:02:04 +0100
commitfd98985f82cd6a6bb71f4653455d2709c3da5b82 (patch)
treeac9845eaf48231ed615e571da4cf81c15db7f2ed
parent5caf6d31f90a502ad0ca7cd1e222d84e67b77259 (diff)
parentb714eeba4163c03532ac9cd017095dba8932a81c (diff)
downloadqtxmlpatterns-fd98985f82cd6a6bb71f4653455d2709c3da5b82.tar.gz
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I3eb54f906dc1ee8fedf64a4cde67edb3f8ce5460
-rw-r--r--src/xmlpatterns/schema/qxsdschemahelper.cpp2
-rw-r--r--src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp10
-rw-r--r--tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xml6
-rw-r--r--tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xsd36
-rw-r--r--tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp23
5 files changed, 76 insertions, 1 deletions
diff --git a/src/xmlpatterns/schema/qxsdschemahelper.cpp b/src/xmlpatterns/schema/qxsdschemahelper.cpp
index 843e7c5..1123e4f 100644
--- a/src/xmlpatterns/schema/qxsdschemahelper.cpp
+++ b/src/xmlpatterns/schema/qxsdschemahelper.cpp
@@ -518,7 +518,7 @@ bool XsdSchemaHelper::constructAndCompare(const DerivedString<TypeString>::Ptr &
const ReportContext::Ptr &context,
const SourceLocationReflection *const sourceLocationReflection)
{
- Q_ASSERT_X(type->category() == SchemaType::SimpleTypeAtomic, Q_FUNC_INFO,
+ Q_ASSERT_X(type && type->category() == SchemaType::SimpleTypeAtomic, Q_FUNC_INFO,
"We can only compare atomic values.");
// we can not cast a xs:String to a xs:QName, so lets go the safe way
diff --git a/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp b/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp
index 7661569..f1b4014 100644
--- a/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp
+++ b/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp
@@ -1113,6 +1113,7 @@ bool XsdValidatingInstanceReader::selectNodeSets(const XsdElement::Ptr&, const Q
const QXmlNodeModelIndex index = fieldItem.toNodeModelIndex();
const SchemaType::Ptr type = m_model->assignedType(index);
+ Q_ASSERT(type);
bool typeOk = true;
if (type->isComplexType()) {
@@ -1136,6 +1137,15 @@ bool XsdValidatingInstanceReader::selectNodeSets(const XsdElement::Ptr&, const Q
targetType = XsdSimpleType::Ptr(type)->primitiveType();
else
targetType = XsdComplexType::Ptr(type)->contentType()->simpleType();
+
+ if (!targetType) {
+ // QTBUG-77620: pattern type within a union doesn't get
+ // its primitive type set. FIXME: find root cause and
+ // fix that, so we can remove this (and an XFAIL).
+ error(QtXmlPatterns::tr("Field %1 is missing its simple type.")
+ .arg(formatData(field->expression())));
+ return false;
+ }
} else {
if (BuiltinTypes::xsAnySimpleType->name(m_namePool) == type->name(m_namePool)) {
targetType = BuiltinTypes::xsString;
diff --git a/tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xml b/tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xml
new file mode 100644
index 0000000..1bde466
--- /dev/null
+++ b/tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<root>
+ <item key="KEY1" />
+ <item key="KEY2" />
+ <item key="CUSTOM_KEY1" />
+</root>
diff --git a/tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xsd b/tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xsd
new file mode 100644
index 0000000..33657c7
--- /dev/null
+++ b/tests/auto/qxmlschemavalidator/testdata/QTBUG-77620.xsd
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:simpleType name="pattern_type">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="CUSTOM_[0-9a-zA-Z]+" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="enum_type">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="KEY1" />
+ <xs:enumeration value="KEY2" />
+ <!-- Note: *no* matching entry for key "CUSTOM_KEY1" -->
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="union_type">
+ <xs:union memberTypes="enum_type pattern_type" />
+ </xs:simpleType>
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="item" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:attribute name="key" type="union_type" use="required" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:key name="primary_key">
+ <xs:selector xpath="./item" />
+ <xs:field xpath="@key" />
+ </xs:key>
+ </xs:element>
+</xs:schema>
diff --git a/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp b/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp
index b128bef..51ef07d 100644
--- a/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp
+++ b/tests/auto/qxmlschemavalidator/tst_qxmlschemavalidator.cpp
@@ -74,6 +74,8 @@ private Q_SLOTS:
void uriResolverSignature() const;
void uriResolverDefaultValue() const;
void uriResolver() const;
+
+ void unionCrash() const;
};
static QXmlSchema createValidSchema()
@@ -456,6 +458,27 @@ void tst_QXmlSchemaValidator::uriResolver() const
}
}
+void tst_QXmlSchemaValidator::unionCrash() const
+{
+ // Regression test for QTBUG-77620 (segfault on nullptr dereference).
+ const QString path = QFINDTESTDATA("testdata/");
+ QXmlSchema schema;
+
+ const QString filePath = path + QLatin1String("QTBUG-77620.xsd");
+
+ QFile file(filePath);
+ QVERIFY(file.open(QIODevice::ReadOnly));
+
+ schema.load(file.readAll(), QUrl(filePath));
+ QVERIFY2(schema.isValid(), "Schema should be found valid.");
+ // Validate instance
+ QXmlSchemaValidator validator(schema);
+ QEXPECT_FAIL("", "QTBUG-77620: " // Fixed crash, but not underlying problem:
+ "the code fails to record the CUSTOM_KEY's primitive type as pattern_type", Continue);
+ QVERIFY2(validator.validate(QUrl(path + QLatin1String("QTBUG-77620.xml"))),
+ "Document should be found valid");
+}
+
QTEST_MAIN(tst_QXmlSchemaValidator)
#include "tst_qxmlschemavalidator.moc"