From 22d475e1ef32875c4933b2bb4c2830cb1bdd3266 Mon Sep 17 00:00:00 2001 From: Juha Kukkonen Date: Mon, 10 Oct 2011 08:36:14 +0300 Subject: Fix XML schema validation failure. Checking constraining facets for double failed if enumeration restriction had values INF or NaN. There were two issues that caused validation to fail: - wrong conversion function was used when constraining facets for double are checked, which caused values to be in lower case - case when both restriction and default value are NaN was not handled correctly Task-number: QTBUG-21375 Reviewed-by: Honglei Zhang --- src/xmlpatterns/schema/qxsdtypechecker.cpp | 11 ++++++- .../files/schema-with-restrictions.xsd | 37 ++++++++++++++++++++++ .../tst_xmlpatternsvalidator.cpp | 5 +++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/auto/xmlpatternsvalidator/files/schema-with-restrictions.xsd 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::Ptr valueStr = DerivedString::fromLexical(m_namePool, QString::number(value)); + const Numeric::Ptr valuePtr = Double::fromValue(value); + const DerivedString::Ptr valueStr = DerivedString::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 >()->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 @@ + + + + + Test for QTBUG-21375: xmlpatternsvalidator does not allow for non-numeric literals in xsd:double attributes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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) -- cgit v0.12