Skip to content

Commit

Permalink
add urldecode function (opentofu#1234)
Browse files Browse the repository at this point in the history
Signed-off-by: pooriaghaedi <[email protected]>
  • Loading branch information
pooriaghaedi committed Feb 23, 2024
1 parent e566f2b commit 7972534
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
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
20 changes: 4 additions & 16 deletions internal/lang/funcs/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -347,21 +347,6 @@ func TestURLEncodeDecode(t *testing.T) {
cty.StringVal("foo/bar"),
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%00, bar!"),
Expand All @@ -372,6 +357,9 @@ func TestURLEncodeDecode(t *testing.T) {
for _, test := range tests {
t.Run(fmt.Sprintf("url encode decode(%#v)", test.String), func(t *testing.T) {
encoded, err := URLEncode(test.String)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
got, err := URLDecode(encoded)

if test.Err {
Expand Down

0 comments on commit 7972534

Please sign in to comment.