Skip to content

Commit

Permalink
🐞: Allow spaces in app names
Browse files Browse the repository at this point in the history
This regression was introduced while trying to fix [another
bug](https://www.pivotaltracker.com/story/show/172891571), preventing
users from logging in to spaces containing commas in the name.

Commas should be the only special character requiring double encoding
(per [this documentation](https://github.com/cloudfoundry/cc-api-v3-style-guide#query-parameters),
so we are now using a find replace for commas only.

[finishes #173550835]

Authored-by: Sarah Weinstein <[email protected]>
  • Loading branch information
sweinstein22 committed Jul 8, 2020
1 parent 758080a commit 75ab163
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion api/cloudcontroller/ccv3/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func FormatQueryParameters(queries []Query) url.Values {
if query.Key == NameFilter {
encodedParamValues := []string{}
for _, valString := range query.Values {
encodedParamValues = append(encodedParamValues, url.QueryEscape(valString))
commaEncoded := strings.ReplaceAll(valString, ",", "%2C")
encodedParamValues = append(encodedParamValues, commaEncoded)
}
query.Values = encodedParamValues
}
Expand Down
6 changes: 3 additions & 3 deletions api/cloudcontroller/ccv3/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var _ = Describe("Query Helpers", func() {
inputQueries = []Query{
{
Key: NameFilter,
Values: []string{"name1", "name,2"},
Values: []string{"name1", "name,2", "name 3"},
},
}
outputParameters = FormatQueryParameters(inputQueries)
})

It("encodes the param values before formatting", func() {
It("encodes commas before formatting", func() {
Expect(outputParameters).To(Equal(url.Values{
"names": []string{"name1,name%2C2"},
"names": []string{"name1,name%2C2,name 3"},
}))
})
})
Expand Down

0 comments on commit 75ab163

Please sign in to comment.