Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictionary keys and values incorrectly serialize some strings #493

Open
Coleoid opened this issue May 14, 2020 · 1 comment
Open

Dictionary keys and values incorrectly serialize some strings #493

Coleoid opened this issue May 14, 2020 · 1 comment
Labels

Comments

@Coleoid
Copy link

Coleoid commented May 14, 2020

The ones I found were tilde, tab, and newline by themselves, or newline within a string.

I'm unclear on the correct fix, so I don't have a PR for you, but here's a test set:

[Theory]
[MemberData(nameof(BuggedString_TestCases))]
public void Some_strings_fail_to_roundtrip_as_a_dictionary_key_or_value(string val)
{
    var obj = new Dictionary<string, string> {
        { val, val },
    };

    var result = DoRoundtripFromObjectTo<Dictionary<string, string>>(obj);

    result.Should().Equal(obj);
    //  The failing strings need quoting and don't get them.
}

public static IEnumerable<Object[]> BuggedString_TestCases
{
    //  All these values correctly round-trip as simple strings.
    get
    {
        //  These values fail to round-trip correctly as key or value in a dictionary.
        yield return new Object[] { "~" };
        yield return new Object[] { "\n" };
        yield return new Object[] { "\t" };
        yield return new Object[] { "x\nx" };

        //  These values round-trip correctly despite similarity to failing cases.
        yield return new Object[] { "x~x" };
        yield return new Object[] { "x\tx" };
        yield return new Object[] { " ~ " };
        yield return new Object[] { " \n " };
        yield return new Object[] { " \t " };
    }
}
@aaubry
Copy link
Owner

aaubry commented May 14, 2020

Thanks for reporting this. I'll need some time to look into this in order to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants