Skip to content

Commit

Permalink
Total digits invalid cast exception (dotnet#34463)
Browse files Browse the repository at this point in the history
* Changed comparison so that it no longer casts Int32 values to Decimal.
  • Loading branch information
mrj001 authored Apr 26, 2020
1 parent 3cf050a commit b93693e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ internal void CompileTotalDigitsFacet(XmlSchemaFacet facet)

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,5 +1092,36 @@ public void AllRefMinMax_Throws(string schema)
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();
}
}
}
}

0 comments on commit b93693e

Please sign in to comment.