Skip to content

Commit acf21a8

Browse files
committed
Fix escaping for context name in API call
1 parent 21ffede commit acf21a8

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: client/context.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (context *Context) GetID() string {
3232
}
3333

3434
func (client *Client) GetContext(name string) (*Context, error) {
35-
fullPath := fmt.Sprintf("/contexts/%s?decrypt=true", url.QueryEscape(name))
35+
fullPath := fmt.Sprintf("/contexts/%s?decrypt=true", url.PathEscape(name))
3636
opts := RequestOptions{
3737
Path: fullPath,
3838
Method: "GET",
@@ -91,7 +91,7 @@ func (client *Client) UpdateContext(context *Context) (*Context, error) {
9191
return nil, err
9292
}
9393

94-
fullPath := fmt.Sprintf("/contexts/%s", url.QueryEscape(context.Metadata.Name))
94+
fullPath := fmt.Sprintf("/contexts/%s", url.PathEscape(context.Metadata.Name))
9595
opts := RequestOptions{
9696
Path: fullPath,
9797
Method: "PUT",
@@ -116,7 +116,7 @@ func (client *Client) UpdateContext(context *Context) (*Context, error) {
116116

117117
func (client *Client) DeleteContext(name string) error {
118118

119-
fullPath := fmt.Sprintf("/contexts/%s", url.QueryEscape(name))
119+
fullPath := fmt.Sprintf("/contexts/%s", url.PathEscape(name))
120120
opts := RequestOptions{
121121
Path: fullPath,
122122
Method: "DELETE",

Diff for: codefresh/resource_context_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@ import (
1313

1414
var contextNamePrefix = "TerraformAccTest_"
1515

16+
func TestAccCodefreshContextConfigWithCharactersToBeEscaped(t *testing.T) {
17+
name := contextNamePrefix + "cf ctx/test +?#@ special" + acctest.RandString(10)
18+
resourceName := "codefresh_context.test"
19+
20+
resource.ParallelTest(t, resource.TestCase{
21+
PreCheck: func() { testAccPreCheck(t) },
22+
Providers: testAccProviders,
23+
CheckDestroy: testAccCheckCodefreshContextDestroy,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccCodefreshContextConfig(name, "config1", "value1", "config2", "value2"),
27+
Check: resource.ComposeTestCheckFunc(
28+
testAccCheckCodefreshContextExists(resourceName),
29+
resource.TestCheckResourceAttr(resourceName, "name", name),
30+
resource.TestCheckResourceAttr(resourceName, "spec.0.config.0.data.config1", "value1"),
31+
resource.TestCheckResourceAttr(resourceName, "spec.0.config.0.data.config2", "value2"),
32+
),
33+
},
34+
{
35+
ResourceName: resourceName,
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
},
39+
},
40+
})
41+
}
42+
1643
func TestAccCodefreshContextConfig(t *testing.T) {
1744
name := contextNamePrefix + acctest.RandString(10)
1845
resourceName := "codefresh_context.test"

0 commit comments

Comments
 (0)