nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gin-gonic/gin
Pull request #2166 (2019-12-03 13:25:38)

Fixed a bug in the calculation of the maximum number of parameters
sync httprouter:
https://github.com/julienschmidt/httprouter/pull/261


codecov[bot]: # [Codecov](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=h1) Report
> Merging [#2166](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=desc) into [master](https://codecov.io/gh/gin-gonic/gin/commit/77b83441698ffcc400d02b9849f15d7a47e0b8bc?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/gin-gonic/gin/pull/2166/graphs/tree.svg?width=650&token=Qpqxhwery8&height=150&src=pr)](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2166      +/-   ##
==========================================
+ Coverage   98.61%   98.61%   +<.01%     
==========================================
  Files          40       40              
  Lines        2242     2244       +2     
==========================================
+ Hits         2211     2213       +2     
  Misses         16       16              
  Partials       15       15
```


| [Impacted Files](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tree.go](https://codecov.io/gh/gin-gonic/gin/pull/2166/diff?src=pr&el=tree#diff-dHJlZS5nbw==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=footer). Last update [77b8344...6e18fc6](https://codecov.io/gh/gin-gonic/gin/pull/2166?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/tree.go b/tree.go
index 1187f3f..b46ec82 100644
--- a/tree.go
+++ b/tree.go
@@ -357,6 +357,10 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
 				maxParams: 1,
 				fullPath:  fullPath,
 			}
+			// update maxParams of the parent node
+			if n.maxParams < 1 {
+				n.maxParams = 1
+			}
 			n.children = []*node{child}
 			n.indices = string(path[i])
 			n = child


Test patch:
diff --git a/tree_test.go b/tree_test.go
index e6e2886..0fe2fe0 100644
--- a/tree_test.go
+++ b/tree_test.go
@@ -368,6 +368,13 @@ func TestTreeCatchAllConflictRoot(t *testing.T) {
 	testRoutes(t, routes)
 }
 
+func TestTreeCatchMaxParams(t *testing.T) {
+	tree := &node{}
+	var route = "/cmd/*filepath"
+	tree.addRoute(route, fakeHandler(route))
+	checkMaxParams(t, tree)
+}
+
 func TestTreeDoubleWildcard(t *testing.T) {
 	const panicMsg = "only one wildcard per path segment is allowed"
Repository: gin-gonic/gin
Pull request #3139 (2022-05-05 09:39:12)

feat: automatically SetMode to TestMode when run go test.
related issue: https://github.com/gin-gonic/gin/issues/3134




appleboy: Need @thinkerou approval.

Patch:
diff --git a/mode.go b/mode.go
index 1fb994b..4e7d734 100644
--- a/mode.go
+++ b/mode.go
@@ -5,6 +5,7 @@
 package gin
 
 import (
+	"flag"
 	"io"
 	"os"
 
@@ -54,7 +55,11 @@ func init() {
 // SetMode sets gin mode according to input string.
 func SetMode(value string) {
 	if value == "" {
-		value = DebugMode
+		if flag.Lookup("test.v") != nil {
+			value = TestMode
+		} else {
+			value = DebugMode
+		}
 	}
 
 	switch value {


Test patch:
diff --git a/mode_test.go b/mode_test.go
index 1b5fb2f..6fd9a13 100644
--- a/mode_test.go
+++ b/mode_test.go
@@ -5,6 +5,7 @@
 package gin
 
 import (
+	"flag"
 	"os"
 	"testing"
 
@@ -21,9 +22,16 @@ func TestSetMode(t *testing.T) {
 	assert.Equal(t, TestMode, Mode())
 	os.Unsetenv(EnvGinMode)
 
+	SetMode("")
+	assert.Equal(t, testCode, ginMode)
+	assert.Equal(t, TestMode, Mode())
+
+	tmp := flag.CommandLine
+	flag.CommandLine = flag.NewFlagSet("", flag.ContinueOnError)
 	SetMode("")
 	assert.Equal(t, debugCode, ginMode)
 	assert.Equal(t, DebugMode, Mode())
+	flag.CommandLine = tmp
 
 	SetMode(DebugMode)
 	assert.Equal(t, debugCode, ginMode)
Repository: gin-gonic/gin
Pull request #3784 (2023-11-27 20:10:26)

fix(route): Add fullPath in context copy
### Summary

When a gin.Context was copied using the Copy method, fullPath was not getting copied to the new context. This PR fixes it by copying the fullPath to the new context

KarthikReddyPuli: @appleboy can you please review and merge this PR ?
appleboy: @KarthikReddyPuli Please help to fix conflcts.

Patch:
diff --git a/context.go b/context.go
index 126d35d..609827d 100644
--- a/context.go
+++ b/context.go
@@ -120,6 +120,7 @@ func (c *Context) Copy() *Context {
 	cp.Writer = &cp.writermem
 	cp.index = abortIndex
 	cp.handlers = nil
+	cp.fullPath = c.fullPath
 
 	cKeys := c.Keys
 	cp.Keys = make(map[string]any, len(cKeys))


Test patch:
diff --git a/context_test.go b/context_test.go
index d060ccf..ac766e2 100644
--- a/context_test.go
+++ b/context_test.go
@@ -324,6 +324,7 @@ func TestContextCopy(t *testing.T) {
 	c.handlers = HandlersChain{func(c *Context) {}}
 	c.Params = Params{Param{Key: "foo", Value: "bar"}}
 	c.Set("foo", "bar")
+	c.fullPath = "/hola"
 
 	cp := c.Copy()
 	assert.Nil(t, cp.handlers)
@@ -336,6 +337,7 @@ func TestContextCopy(t *testing.T) {
 	assert.Equal(t, cp.Params, c.Params)
 	cp.Set("foo", "notBar")
 	assert.False(t, cp.Keys["foo"] == c.Keys["foo"])
+	assert.Equal(t, cp.fullPath, c.fullPath)
 }
 
 func TestContextHandlerName(t *testing.T) {
Repository: gin-gonic/gin
Pull request #3899 (2024-03-21 14:30:35)

Revert "fix(uri): query binding bug"
Reverts gin-gonic/gin#3236

appleboy: @thinkerou Please help to review and merge asap.
flc1125: 😅

Patch:
diff --git a/binding/query.go b/binding/query.go
index baa4aea..c958b88 100644
--- a/binding/query.go
+++ b/binding/query.go
@@ -12,9 +12,9 @@ func (queryBinding) Name() string {
 	return "query"
 }
 
-func (q queryBinding) Bind(req *http.Request, obj any) error {
+func (queryBinding) Bind(req *http.Request, obj any) error {
 	values := req.URL.Query()
-	if err := mapFormByTag(obj, values, q.Name()); err != nil {
+	if err := mapForm(obj, values); err != nil {
 		return err
 	}
 	return validate(obj)


Test patch:
diff --git a/binding/query_test.go b/binding/query_test.go
deleted file mode 100644
index 7210204..0000000
--- a/binding/query_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package binding
-
-import (
-	"net/http"
-	"net/url"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-)
-
-func TestQueryBinding(t *testing.T) {
-	var s struct {
-		Foo string `query:"foo"`
-	}
-
-	request := &http.Request{URL: &url.URL{RawQuery: "foo=BAR"}}
-
-	err := queryBinding{}.Bind(request, &s)
-	require.NoError(t, err)
-
-	assert.Equal(t, "BAR", s.Foo)
-}