-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Add PureJSON renderer #694
Merged
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6613cdb
fix cleanPath spell (#969)
thinkerou 79478c0
Merge branch 'master' into develop
appleboy ddb175b
Add PureJSON for rendering unescaped json data
ffigiel 5676689
Gofmt
ffigiel 5c70490
Fix missing NewEncoder
ffigiel f019519
Fix tests style
ffigiel 2000a13
Extract a method for writing content type
ffigiel fa2e05a
Create test context properly
ffigiel 147b479
Update expected json content
ffigiel 786a213
Add readme section about PureJSON
ffigiel a682226
Don't include PureJSON in Go 1.6 and lower
ffigiel df00f24
Remove unused imports
ffigiel ac48b84
Remove unused imports
ffigiel 4152da4
Re-run CI build
ffigiel a84483b
Update copyrights for new files
ffigiel fbe37a5
Apply requested changes
ffigiel ee988b5
Merge remote-tracking branch 'upstream/master' into PureJSON
ffigiel b1cf3bf
Fix test
ffigiel a847321
Fix test
ffigiel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,30 @@ func TestRenderMsgPack(t *testing.T) { | |
func TestRenderJSON(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
data := map[string]interface{}{ | ||
"foo": "bar", | ||
"foo": "bar", | ||
"html": "<b>", | ||
} | ||
|
||
err := (JSON{data}).Render(w) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String()) | ||
assert.Equal( | ||
t, | ||
w.Body.String(), | ||
"{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}\n") | ||
assert.Equal(t, w.Header().Get("Content-Type"), "application/json; charset=utf-8") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
} | ||
|
||
func TestRenderPureJSON(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
data := map[string]interface{}{ | ||
"foo": "bar", | ||
"html": "<b>", | ||
} | ||
err := (PureJSON{data}).Render(w) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String()) | ||
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type")) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to use one line