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

Fix isJSON() to recognize leading tabs and new line characters #1424

Merged
merged 3 commits into from Jul 28, 2017

Conversation

hkosova
Copy link
Contributor

@hkosova hkosova commented Jul 27, 2017

When a user pastes JSON into the editor, the editor prompts to convert it to YAML. This works if the JSON contains leading spaces:

  	 {"foo": "bar"}

but does not currently work if the leading whitespace includes new line characters or tabs -- in this case JSON is pasted "as is".

 
 
{"foo": "bar"}

This PR improves the isJSON() function to recognize \t, \r and \n in the leading whitespace. Tabs and new lines are allowed in the leading whitespace according to RFC 4627 (section 2) and ECMA-404 (section 4):

Insignificant whitespace is allowed before or after any of the six structural characters.

The whitespace characters are: character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020).

When a user pastes JSON into the editor, the editor prompts to convert it to YAML. This works if the JSON contains leading spaces:
```
  	 {"foo": "bar"}
```
but does not currently work if the leading whitespace includes new line characters or tabs -- in this case JSON is pasted "as is".
```


{"foo": "bar"}
```

This PR improves the `isJSON()` function to recognize `\t`, `\r` and `\n` in the leading whitespace. Tabs and new lines are allowed in the leading whitespace according to [RFC 4627](https://tools.ietf.org/html/rfc4627) (section 2) and [ECMA-404](https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) (section 4):
> Insignificant whitespace is allowed before or after any of the six structural characters.
> 
> The whitespace characters are: character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020).
@webron webron requested a review from shockey July 28, 2017 02:41
@shockey shockey merged commit 89af89e into swagger-api:master Jul 28, 2017
@hkosova hkosova deleted the patch-1 branch July 29, 2017 13:25
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

Successfully merging this pull request may close these issues.

None yet

2 participants