-
Notifications
You must be signed in to change notification settings - Fork 941
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Double encode name parameters in requests to CAPI
The v3 API requires that the comma character is double encoded when used in a single query parameter. Previously, the CLI would only encode the query request once it was fully formed. This was sufficient for v2, but with the v3 API this would cause issues when using a resource that had commas in its name. This commit now encodes query parameters with the `names` filter before encoding the entire query. This ensures that resource names that may contain commas are properly double encoded. [Github issue #1938](#1938) [#172891571](https://www.pivotaltracker.com/story/show/172891571) Authored-by: Belinda Liu <bliu@pivotal.io>
- Loading branch information
1 parent
e5d7012
commit 45b2481
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ccv3_test | ||
|
||
import ( | ||
"net/url" | ||
|
||
. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Query Helpers", func() { | ||
Describe("FormatQueryParameters", func() { | ||
var ( | ||
inputQueries []Query | ||
outputParameters url.Values | ||
) | ||
|
||
BeforeEach(func() { | ||
inputQueries = []Query{ | ||
{ | ||
Key: SpaceGUIDFilter, | ||
Values: []string{"space-guid1", "space-guid2"}, | ||
}, | ||
} | ||
outputParameters = FormatQueryParameters(inputQueries) | ||
}) | ||
|
||
It("encodes the param values and reformats the query", func() { | ||
Expect(outputParameters).To(Equal(url.Values{ | ||
"space_guids": []string{"space-guid1,space-guid2"}, | ||
})) | ||
}) | ||
|
||
When("the name filter is used", func() { | ||
BeforeEach(func() { | ||
inputQueries = []Query{ | ||
{ | ||
Key: NameFilter, | ||
Values: []string{"name1", "name,2"}, | ||
}, | ||
} | ||
outputParameters = FormatQueryParameters(inputQueries) | ||
}) | ||
|
||
It("encodes the param values before formatting", func() { | ||
Expect(outputParameters).To(Equal(url.Values{ | ||
"names": []string{"name1,name%2C2"}, | ||
})) | ||
}) | ||
}) | ||
}) | ||
}) |