Add the url_encode filter (#50)

This commit is contained in:
Colin Morris 2021-11-18 23:09:54 +10:00 committed by GitHub
parent 355c7f2be5
commit c01fa5d162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"math"
"net/url"
"sort"
"strings"
"unicode/utf8"
@ -503,6 +504,5 @@ func filterUpper(ctx stick.Context, val stick.Value, args ...stick.Value) stick.
}
func filterURLEncode(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
// TODO: Implement Me
return val
return url.QueryEscape(stick.CoerceString(val))
}

View file

@ -129,6 +129,7 @@ func TestFilters(t *testing.T) {
return
},
},
{"urlencode", func() stick.Value { return filterURLEncode(nil, "http://test.com/dude?sweet=33&1=2") }, "http%3A%2F%2Ftest.com%2Fdude%3Fsweet%3D33%261%3D2"},
}
for _, test := range tests {
matches := false