Skip to content

JSONObject: tabs should not be allowed #240

Closed
@mmoghadas

Description

@mmoghadas

If I'm understanding the JSON standards correctly, tabs are not allowed. I'm posting a json to my api (the whitespace at the end of the value is a tab character). This is what's happening in the background:

String string = {"key":"value "};
JSONObject json;
try {
json = new JSONObject(string);
} catch (JSONException e) {
}

the assignment above should not succeed, but it does.
you can use this sample project to see for yourself
https://github.com/mmoghadas/gs-rest-service/blob/master/complete/src/main/java/hello/GreetingController.java#L26

git clone git@github.com:mmoghadas/gs-rest-service.git
cd gs-rest-service/complete
./gradlew build
java -jar build/libs/gs-rest-service-0.1.0.jar

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
Insignificant whitespace is allowed before or after any token. The whitespace characters are: character
tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020). Whitespace is not allowed within any token, except that space is allowed in strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions