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

cogito: properly encode url #153

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cogito/putter.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ func concourseBuildURL(env Environment) string {
// https://ci.example.com/teams/main/pipelines/cogito/jobs/autocat/builds/3?vars=%7B%22branch%22%3A%22stable%22%7D
if env.BuildPipelineInstanceVars != "" {
buildURL += fmt.Sprintf("?vars=%s", url.QueryEscape(env.BuildPipelineInstanceVars))
// Concourse requires that the space characters
// are encoded as %20 instead of +. On the other hand
// golangs url.QueryEscape as well as url.Values.Encode()
// both encode the space as a + character.
// See: https://github.com/golang/go/issues/4013
buildURL = strings.ReplaceAll(buildURL, "+", "%20")
marco-m-pix4d marked this conversation as resolved.
Show resolved Hide resolved
}

return buildURL
Expand Down
16 changes: 14 additions & 2 deletions cogito/putter_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,29 @@ func TestConcourseBuildURL(t *testing.T) {
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42",
},
{
name: "instanced vars 1",
name: "single instance variable",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"stable"}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars=%7B%22branch%22%3A%22stable%22%7D",
},
{
name: "instanced vars 2",
name: "single instance variable with spaces",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"foo bar"}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars=%7B%22branch%22%3A%22foo%20bar%22%7D",
},
{
name: "multiple instance variables",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"stable","foo":"bar"}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars=%7B%22branch%22%3A%22stable%22%2C%22foo%22%3A%22bar%22%7D",
},
{
name: "multiple instance variables: nested json with spaces",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"foo bar","version":{"from":1.0,"to":2.0}}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars=%7B%22branch%22%3A%22foo%20bar%22%2C%22version%22%3A%7B%22from%22%3A1.0%2C%22to%22%3A2.0%7D%7D",
},
}

for _, tc := range testCases {
Expand Down
Loading