diff options
author | Juha Kukkonen <juha.kukkonen@nokia.com> | 2011-10-10 05:36:14 (GMT) |
---|---|---|
committer | Juha Kukkonen <juha.kukkonen@nokia.com> | 2011-10-10 07:15:23 (GMT) |
commit | 22d475e1ef32875c4933b2bb4c2830cb1bdd3266 (patch) | |
tree | 7959bcba424f1108481e26341c4e9e35e12e152d | |
parent | 7e662f3727e7c3dd3c41c29ed49bc41d2b66c744 (diff) | |
download | Qt-22d475e1ef32875c4933b2bb4c2830cb1bdd3266.zip Qt-22d475e1ef32875c4933b2bb4c2830cb1bdd3266.tar.gz Qt-22d475e1ef32875c4933b2bb4c2830cb1bdd3266.tar.bz2 |
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
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) |