Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix a bug in xsd validation during deserialization#37596

Merged
jiayi11 merged 2 commits intodotnet:masterfrom
jiayi11:xsdvalidating
May 17, 2019
Merged

Fix a bug in xsd validation during deserialization#37596
jiayi11 merged 2 commits intodotnet:masterfrom
jiayi11:xsdvalidating

Conversation

@jiayi11
Copy link
Copy Markdown
Member

@jiayi11 jiayi11 commented May 10, 2019

Fixes #36819

@jiayi11 jiayi11 self-assigned this May 10, 2019
@jiayi11 jiayi11 added this to the 3.0 milestone May 10, 2019
@drieseng
Copy link
Copy Markdown
Contributor

@yujayee Add a corresponding regression test?

@drieseng
Copy link
Copy Markdown
Contributor

Unrelated to this specific bug, but can't you just immediately return typedValue if you know it's a string (hereby bypassing the value converter)?

object typedValue = InternalReadElementContentAsObject(out XmlSchemaType xmlType);
if (typedValue != null)
{
    var stringValue = typedValue as string;
    if (stringValue != null)
    {
        return stringValue;
    }

    if (xmlType != null)
    {
        try
        {
            xmlType.ValueConverter.ToString(typedValue);
        }
        catch (InvalidCastException)
        {
            throw new XmlException();
        }
        catch (FormatException)
        {
            throw new XmlException();
        }
        catch (OverflowException)
        {
            throw new XmlException();
        }
    }
}

return string.Empty;

Based on some limited testing, this would make ReadElementContentAsString()about 20% faster when dealing with a string value (which should be the common case, no?).

@jiayi11 jiayi11 requested a review from mconnew May 16, 2019 01:37
@jiayi11
Copy link
Copy Markdown
Member Author

jiayi11 commented May 16, 2019

@drieseng Thanks for reviewing this pr😄 I just added a test for the code change. Xsd validating during deserialization is probably not on a hot code pass. So I wanted to make the code change minimal to make it more clear.

@jiayi11 jiayi11 merged commit 4435d78 into dotnet:master May 17, 2019
@jiayi11 jiayi11 deleted the xsdvalidating branch May 17, 2019 00:20
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Fix a bug in xsd validation during deserialization
* Add a test


Commit migrated from dotnet/corefx@4435d78
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XSD Validation throws an exception when self-closing tag used

3 participants