Skip to content

Commit

Permalink
fix: use escaped strings for services' path
Browse files Browse the repository at this point in the history
Right now, when a `url` containing an encoded whitespace (`%20`)
is passed to a service, decK unwraps it and replace it with an
actual whitespace. This is because decK uses `url.Parse` under
the cover, which is the one making this translation.

This commit makes decK URL unwrapping method to encode back
decoded whitespaces.
  • Loading branch information
GGabriele committed Oct 6, 2022
1 parent af2bb91 commit 9997f56
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of Contents

- [Unreleased](#Unreleased)
- [v1.15.1](#v1151)
- [v1.15.0](#v1150)
- [v1.14.0](#v1140)
Expand Down Expand Up @@ -45,6 +46,15 @@
- [v0.2.0](#v020)
- [v0.1.0](#v010)

## [Unreleased]

> Release date: TBD
### Fixes

- Handle correctly encoded whitespaces into services' `url`
[#755](https://github.com/Kong/deck/pull/755)

## [v1.15.1]

> Release date: 2022/09/27
Expand Down Expand Up @@ -1031,6 +1041,7 @@ No breaking changes have been introduced in this release.

Debut release of decK

[Unreleased]: https://github.com/kong/deck/compare/v1.15.1...Unreleased
[v1.15.1]: https://github.com/kong/deck/compare/v1.15.0...v1.15.1
[v1.15.0]: https://github.com/kong/deck/compare/v1.14.0...v1.15.0
[v1.14.0]: https://github.com/kong/deck/compare/v1.13.0...v1.14.0
Expand Down
4 changes: 3 additions & 1 deletion file/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ func unwrapURL(urlString string, fService *FService) error {
}
}
if parsed.Path != "" {
fService.Path = kong.String(parsed.Path)
// make sure that decoded whitespaces are encoded back
encodedParsedPath := strings.ReplaceAll(parsed.Path, " ", "%20")
fService.Path = kong.String(encodedParsedPath)
}
return nil
}
Expand Down
36 changes: 25 additions & 11 deletions file/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
)

var (
jsonString = `{
"name": "rate-limiting",
"config": {
jsonString = `{
"name": "rate-limiting",
"config": {
"minute": 10
},
"service": "foo",
"route": "bar",
"consumer": "baz",
"enabled": true,
"run_on": "first",
"protocols": [
},
"service": "foo",
"route": "bar",
"consumer": "baz",
"enabled": true,
"run_on": "first",
"protocols": [
"http"
]
]
}`
yamlString = `
name: rate-limiting
Expand Down Expand Up @@ -467,6 +467,20 @@ func Test_unwrapURL(t *testing.T) {
},
wantErr: true,
},
{
args: args{
urlString: "http://foo.com/Spaced%20Test/bar",
fService: &FService{
Service: kong.Service{
Host: kong.String("foo.com"),
Protocol: kong.String("http"),
Port: kong.Int(80),
Path: kong.String("/Spaced%20Test/bar"),
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 9997f56

Please sign in to comment.