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

Prevent panic in Context.GetQuery() when there is no Request #2412

Merged
merged 3 commits into from Aug 8, 2020

Conversation

pofl
Copy link
Contributor

@pofl pofl commented Jun 15, 2020

I have an endpoint that uses an optional query parameter via DefaultQuery().
In one unit test case I want to test the route with that parameter.
I write that test as

	w := httptest.NewRecorder()
	c, _ := gin.CreateTestContext(w)
	routeHandler(c)

And this panics when routeHandler() calls c.DefaultQuery() because c.Request == nil.

  • With pull requests:
    • Open your pull request against master
    • Your pull request should have no more than two commits, if not you should squash them.
    • It should pass all tests in the available continuous integration systems such as TravisCI.
    • You should add/modify tests to cover your proposed code changes.
    • If your pull request contains a new feature, please document it on the README.

@codecov
Copy link

codecov bot commented Jun 15, 2020

Codecov Report

Merging #2412 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2412   +/-   ##
=======================================
  Coverage   98.72%   98.72%           
=======================================
  Files          41       41           
  Lines        2356     2359    +3     
=======================================
+ Hits         2326     2329    +3     
  Misses         17       17           
  Partials       13       13           
Impacted Files Coverage Δ
context.go 98.09% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30b5f7e...b453ed1. Read the comment docs.

pofl added 2 commits June 16, 2020 10:01
I have an endpoint that uses an optional query parameter via DefaultQuery(). 
In one unit test case I want to test the route with that parameter.
I write that test as
```go
	w := httptest.NewRecorder()
	c, _ := gin.CreateTestContext(w)
	routeHandler(c)
```
And this panics when routeHandler() calls c.DefaultQuery() because c.Request == nil.
@pofl
Copy link
Contributor Author

pofl commented Jun 16, 2020

I have nothing to add to this PR anymore 😊

Copy link
Member

@thinkerou thinkerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@appleboy appleboy merged commit 815e1ce into gin-gonic:master Aug 8, 2020
@pofl pofl deleted the patch-1 branch August 10, 2020 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants