nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: containous/traefik
Pull request #7058 (2020-07-16 10:22:43)

file parser: skip nil value.
### What does this PR do?

file parser: skip nil value.

### Motivation

allow to manage pointer of bool.

### More

- [x] Added/updated tests
- [ ] Added/updated documentation



Patch:
diff --git a/pkg/config/file/raw_node.go b/pkg/config/file/raw_node.go
index 8b5509ad5..9f9b3857b 100644
--- a/pkg/config/file/raw_node.go
+++ b/pkg/config/file/raw_node.go
@@ -28,6 +28,10 @@ func decodeRaw(node *parser.Node, vData reflect.Value, filters ...string) error
 	sortedKeys := sortKeys(vData, filters)
 
 	for _, key := range sortedKeys {
+		if vData.MapIndex(key).IsNil() {
+			continue
+		}
+
 		value := reflect.ValueOf(vData.MapIndex(key).Interface())
 
 		child := &parser.Node{Name: key.String()}


Test patch:
diff --git a/pkg/config/file/raw_node_test.go b/pkg/config/file/raw_node_test.go
index 5b4ae64ae..6811543cf 100644
--- a/pkg/config/file/raw_node_test.go
+++ b/pkg/config/file/raw_node_test.go
@@ -524,6 +524,20 @@ func Test_decodeRawToNode(t *testing.T) {
 				},
 			},
 		},
+		{
+			desc: "nil value",
+			data: map[string]interface{}{
+				"fii": map[interface{}]interface{}{
+					"fuu": nil,
+				},
+			},
+			expected: &parser.Node{
+				Name: "traefik",
+				Children: []*parser.Node{
+					{Name: "fii"},
+				},
+			},
+		},
 	}
 
 	for _, test := range testCases {
Repository: containous/traefik
Pull request #7109 (2020-07-27 22:21:54)

fix: clean X-Forwarded-Prefix header for the dashboard.

### What does this PR do?

Clean X-Forwarded-Prefix header for the dashboard.

### Motivation

Be safe.

### More

- [x] Added/updated tests
- [ ] Added/updated documentation



Patch:
diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go
index e71252e48..b3168de8e 100644
--- a/pkg/api/dashboard.go
+++ b/pkg/api/dashboard.go
@@ -2,6 +2,7 @@ package api
 
 import (
 	"net/http"
+	"net/url"
 
 	"github.com/containous/traefik/v2/pkg/log"
 	assetfs "github.com/elazarl/go-bindata-assetfs"
@@ -23,11 +24,29 @@ func (g DashboardHandler) Append(router *mux.Router) {
 	// Expose dashboard
 	router.Methods(http.MethodGet).
 		Path("/").
-		HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
-			http.Redirect(response, request, request.Header.Get("X-Forwarded-Prefix")+"/dashboard/", http.StatusFound)
+		HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
+			http.Redirect(resp, req, safePrefix(req)+"/dashboard/", http.StatusFound)
 		})
 
 	router.Methods(http.MethodGet).
 		PathPrefix("/dashboard/").
 		Handler(http.StripPrefix("/dashboard/", http.FileServer(g.Assets)))
 }
+
+func safePrefix(req *http.Request) string {
+	prefix := req.Header.Get("X-Forwarded-Prefix")
+	if prefix == "" {
+		return ""
+	}
+
+	parse, err := url.Parse(prefix)
+	if err != nil {
+		return ""
+	}
+
+	if parse.Host != "" {
+		return ""
+	}
+
+	return parse.Path
+}


Test patch:
diff --git a/pkg/api/dashboard_test.go b/pkg/api/dashboard_test.go
new file mode 100644
index 000000000..c945a7000
--- /dev/null
+++ b/pkg/api/dashboard_test.go
@@ -0,0 +1,54 @@
+package api
+
+import (
+	"net/http"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+)
+
+func Test_safePrefix(t *testing.T) {
+	testCases := []struct {
+		desc     string
+		value    string
+		expected string
+	}{
+		{
+			desc:     "host",
+			value:    "https://example.com",
+			expected: "",
+		},
+		{
+			desc:     "host with path",
+			value:    "https://example.com/foo/bar?test",
+			expected: "",
+		},
+		{
+			desc:     "path",
+			value:    "/foo/bar",
+			expected: "/foo/bar",
+		},
+		{
+			desc:     "path without leading slash",
+			value:    "foo/bar",
+			expected: "foo/bar",
+		},
+	}
+
+	for _, test := range testCases {
+		test := test
+		t.Run(test.desc, func(t *testing.T) {
+			t.Parallel()
+
+			req, err := http.NewRequest(http.MethodGet, "http://localhost", nil)
+			require.NoError(t, err)
+
+			req.Header.Set("X-Forwarded-Prefix", test.value)
+
+			prefix := safePrefix(req)
+
+			assert.Equal(t, test.expected, prefix)
+		})
+	}
+}