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

add urldecode function (#1234) #1

Merged
merged 3 commits into from
Feb 23, 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
4 changes: 4 additions & 0 deletions internal/lang/funcs/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ var DescriptionList = map[string]descriptionEntry{
Description: "`urlencode` applies URL encoding to a given string.",
ParamDescription: []string{""},
},
"urldecode": {
Description: "`urldecode` applies URL decoding to a given encoded string.",
ParamDescription: []string{""},
},
"uuid": {
Description: "`uuid` generates a unique identifier string.",
ParamDescription: []string{},
Expand Down
4 changes: 2 additions & 2 deletions internal/lang/funcs/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ var URLEncodeFunc = function.New(&function.Spec{
},
})

// URLDecodeFunc constructs a function that applies URL decoding to a given string.
// URLDecodeFunc constructs a function that applies URL decoding to a given encoded string.
var URLDecodeFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Expand Down Expand Up @@ -301,7 +301,7 @@ func URLEncode(str cty.Value) (cty.Value, error) {
return URLEncodeFunc.Call([]cty.Value{str})
}

// URLDecode decodes a URL-encoded string.
// URLDecode decodes a URL encoded string.
//
// This function decodes the given string that has been encoded.
//
Expand Down
24 changes: 4 additions & 20 deletions internal/lang/funcs/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ func TestURLDecode(t *testing.T) {
false,
},
{
cty.StringVal("foo/bar"),
cty.StringVal("foo%2Fbar"),
cty.StringVal("foo/bar"),
false,
},
{
Expand All @@ -286,7 +286,7 @@ func TestURLDecode(t *testing.T) {
},
{
cty.StringVal("foo%00, bar!"),
cty.StringVal("foo, bar!"),
cty.StringVal("foo\x00, bar!"),
false,
},
{
Expand Down Expand Up @@ -348,23 +348,8 @@ func TestURLEncodeDecode(t *testing.T) {
false,
},
{
cty.StringVal("foo% bar"),
cty.UnknownVal(cty.String),
true,
},
{
cty.StringVal("foo%2 bar"),
cty.UnknownVal(cty.String),
true,
},
{
cty.StringVal("%GGfoo%2bar"),
cty.UnknownVal(cty.String),
true,
},
{
cty.StringVal("foo%00, bar!"),
cty.StringVal("foo, bar!"),
cty.StringVal("foo%00, bar!"),
false,
},
}
Expand All @@ -373,8 +358,7 @@ func TestURLEncodeDecode(t *testing.T) {
t.Run(fmt.Sprintf("url encode decode(%#v)", test.String), func(t *testing.T) {
encoded, err := URLEncode(test.String)
if err != nil {
t.Errorf("encode() error = %v, wantErr = false", err)
return
t.Fatalf("unexpected error: %s", err)
}
got, err := URLDecode(encoded)

Expand Down
Loading