summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/xmlpatterns/schema/qxsdtypechecker.cpp11
-rw-r--r--tests/auto/xmlpatternsvalidator/files/schema-with-restrictions.xsd37
-rw-r--r--tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp5
3 files changed, 52 insertions, 1 deletions
diff --git a/src/xmlpatterns/schema/qxsdtypechecker.cpp b/src/xmlpatterns/schema/qxsdtypechecker.cpp
index fb47448..e5709ae 100644
--- a/src/xmlpatterns/schema/qxsdtypechecker.cpp
+++ b/src/xmlpatterns/schema/qxsdtypechecker.cpp
@@ -57,6 +57,7 @@
#include "qxsdschemahelper_p.h"
#include "qxsdschemamerger_p.h"
#include "qxsdstatemachine_p.h"
+#include "qabstractfloat_p.h"
#include "qxsdschemadebugger_p.h"
@@ -697,7 +698,8 @@ bool XsdTypeChecker::checkConstrainingFacetsDouble(double value, const QString &
}
if (facets.contains(XsdFacet::Enumeration)) {
const XsdFacet::Ptr facet = facets.value(XsdFacet::Enumeration);
- const DerivedString<TypeString>::Ptr valueStr = DerivedString<TypeString>::fromLexical(m_namePool, QString::number(value));
+ const Numeric::Ptr valuePtr = Double::fromValue(value);
+ const DerivedString<TypeString>::Ptr valueStr = DerivedString<TypeString>::fromLexical(m_namePool, valuePtr->stringValue());
const AtomicValue::List multiValue = facet->multiValue();
bool found = false;
@@ -706,6 +708,13 @@ bool XsdTypeChecker::checkConstrainingFacetsDouble(double value, const QString &
found = true;
break;
}
+
+ // Handle case when both facet and value are NaN separately as equals for NaN returns always false.
+ const Numeric::Ptr facetValue = ValueFactory::fromLexical(multiValue.at(j)->as<DerivedString<TypeString> >()->stringValue(), BuiltinTypes::xsDouble, m_context, m_reflection);
+ if (facetValue->isNaN() && valuePtr->isNaN()) {
+ found = true;
+ break;
+ }
}
if (!found) {
diff --git a/tests/auto/xmlpatternsvalidator/files/schema-with-restrictions.xsd b/tests/auto/xmlpatternsvalidator/files/schema-with-restrictions.xsd
new file mode 100644
index 0000000..532efcb
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/schema-with-restrictions.xsd
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:annotation>
+ <xsd:documentation xml:lang="en">
+ Test for QTBUG-21375: xmlpatternsvalidator does not allow for non-numeric literals in xsd:double attributes
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:element name="test1" type="TestType1" />
+ <xsd:element name="test2" type="TestType2" />
+ <xsd:element name="test3" type="TestType3" />
+
+ <xsd:complexType name="TestType1">
+ <xsd:attribute name="attribute1" type="DoubleWithRestrictions" default="INF" />
+ </xsd:complexType>
+
+ <xsd:complexType name="TestType2">
+ <xsd:attribute name="attribute2" type="DoubleWithRestrictions" default="-INF" />
+ </xsd:complexType>
+
+ <xsd:complexType name="TestType3">
+ <xsd:attribute name="attribute3" type="DoubleWithRestrictions" default="NaN" />
+ </xsd:complexType>
+
+ <xsd:simpleType name="DoubleWithRestrictions">
+ <xsd:union>
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:double">
+ <xsd:enumeration value="-INF" />
+ <xsd:enumeration value="INF" />
+ <xsd:enumeration value="NaN" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:union>
+ </xsd:simpleType>
+
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp b/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
index 817ea1a..60c1fe8 100644
--- a/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
+++ b/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
@@ -222,6 +222,11 @@ void tst_XmlPatternsValidator::xsdSupport_data() const
<< (QStringList() << QLatin1String("files/dateTime-with-microseconds.xml")
<< QLatin1String("files/dateTime-with-microseconds.xsd"))
<< QString();
+
+ QTest::newRow("QTBUG-21375 A schema with a xs:double based simple type with non-numeric restrictions")
+ << 0
+ << (QStringList() << QLatin1String("files/schema-with-restrictions.xsd"))
+ << QString();
}
QTEST_MAIN(tst_XmlPatternsValidator)