Bunny83 / SimpleJSON

A simple JSON parser in C#
MIT License
735 stars 294 forks source link

null string implicit conversion #31

Closed ignus2 closed 3 years ago

ignus2 commented 4 years ago

The implicit string -> JSONNode operator doesn't check for null string, and creates a JSONString with null value (null m_Data), which will later cause an exception/crash in Escape() when it is serialized. Suggested fix, replace this:

    public static implicit operator JSONNode(string s)
    {
        return new JSONString(s);
    }

with this:

    public static implicit operator JSONNode(string s)
    {
        return (s == null) ? (JSONNode) JSONNull.CreateOrGet() : new JSONString(s);
    }