Total digits invalid cast exception (#34463)
authormrj001 <62225294+mrj001@users.noreply.github.com>
Sun, 26 Apr 2020 18:58:47 +0000 (12:58 -0600)
committerGitHub <noreply@github.com>
Sun, 26 Apr 2020 18:58:47 +0000 (11:58 -0700)
* Changed comparison so that it no longer casts Int32 values to Decimal.

src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs
src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs

index e04a2f1..050a824 100644 (file)
@@ -309,7 +309,7 @@ namespace System.Xml.Schema
 
                 if ((_baseFixedFlags & RestrictionFlags.TotalDigits) != 0)
                 {
-                    if (!_datatype.IsEqual(_datatype.Restriction.TotalDigits, _derivedRestriction.TotalDigits))
+                    if (_datatype.Restriction.TotalDigits != _derivedRestriction.TotalDigits)
                     {
                         throw new XmlSchemaException(SR.Sch_FacetBaseFixed, facet);
                     }
index 122239c..aafe321 100644 (file)
@@ -1092,5 +1092,36 @@ namespace System.Xml.Tests
             Assert.Contains("maxOccurs", ex.Message);
         }
         #endregion
+
+        [Fact]
+        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
+        public void TotalDigitsParseValue_Succeeds()
+        {
+            string schema = @"<?xml version='1.0' encoding='utf-8' ?>
+<xs:schema elementFormDefault='qualified'
+           xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+    <xs:simpleType name='foo'>
+        <xs:restriction base='xs:decimal'>
+            <xs:totalDigits value='8' fixed='true'/>
+        </xs:restriction>
+    </xs:simpleType>
+    <xs:simpleType name='bar'>
+        <xs:restriction base='foo'>
+            <xs:totalDigits value='8'/>
+        </xs:restriction>
+    </xs:simpleType>
+</xs:schema>
+";
+            using (StringReader srdr = new StringReader(schema))
+            using (XmlReader xmlrdr = XmlReader.Create(srdr))
+            {
+                XmlSchemaSet ss = new XmlSchemaSet();
+
+                ss.Add(null, xmlrdr);
+
+                // Assert does not throw (Regression test for issue #34426)
+                ss.Compile();
+            }
+        }
     }
 }