File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import (
2828 "fmt"
2929 "io"
3030 mathrand "math/rand"
31+ "net/url"
3132 "strings"
3233 "text/template"
3334 "time"
@@ -224,6 +225,17 @@ var advancedFuncs = []AdvancedFunc{{
224225 Func : func () float64 {
225226 return time .Since (uptime ).Seconds ()
226227 },
228+ }, {
229+ FuncName : "urlEncode" ,
230+ Func : func (text string ) string {
231+ return url .QueryEscape (text )
232+ },
233+ }, {
234+ FuncName : "urlDecode" ,
235+ Func : func (text string ) (result string ) {
236+ result , _ = url .QueryUnescape (text )
237+ return
238+ },
227239}}
228240
229241// WeightEnum is a weight enum
Original file line number Diff line number Diff line change @@ -127,6 +127,18 @@ func TestRender(t *testing.T) {
127127 verify : func (t * testing.T , s string ) {
128128 assert .NotEmpty (t , s )
129129 },
130+ }, {
131+ name : "url encode" ,
132+ text : `{{urlEncode "hello world"}}` ,
133+ verify : func (t * testing.T , s string ) {
134+ assert .Equal (t , "hello+world" , s )
135+ },
136+ }, {
137+ name : "url decode" ,
138+ text : `{{urlDecode "hello+world"}}` ,
139+ verify : func (t * testing.T , s string ) {
140+ assert .Equal (t , "hello world" , s )
141+ },
130142 }}
131143 for _ , tt := range tests {
132144 t .Run (tt .name , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments