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

"\0" is invalid JSON #118

Closed
akvadrako opened this issue Dec 9, 2013 · 2 comments
Closed

"\0" is invalid JSON #118

akvadrako opened this issue Dec 9, 2013 · 2 comments

Comments

@akvadrako
Copy link

According the JSON specification, "\0" is not a valid JSON string and must be encoded with four hexadecimal bytes. It's not just a theoretical problem - some python JSON parsers do not accept it.

The BrowserCompatible mode does handle this correctly, but I don't want to escape forward slashes.

I recommend the following unit test:

public class FastJsonTest {
    @Test
    public void testEncodeNulByte() throws Exception {
        String json = JSON.toJSONString("\0");
        assertEquals("\"\\u0000\"", json);
    }
}
@akvadrako
Copy link
Author

Hi. This is quite important to us. I have tried to look at making a patch myself, but this code is fairly complex and I don't want to make a over-reaching change without knowing it would be accepted.

What I don't understand is why the BrowserCompatible code path is so different from the other code path.

@wenshao
Copy link
Member

wenshao commented Oct 2, 2014

bug fixed

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

No branches or pull requests

2 participants