File tree 5 files changed +54
-0
lines changed
5 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 31
31
{:added "1.0"
32
32
:go "queryUnescape(s)"}
33
33
[^String s])
34
+
35
+ (defn parse-query
36
+ "Parses the URL-encoded query string and returns a map listing the vectors of values specified for each key.
37
+ Always returns a non-nil map containing all the valid query parameters found.
38
+ Query is expected to be a list of key=value settings separated by ampersands. A setting without
39
+ an equals sign is interpreted as a key set to an empty value. Settings containing a non-URL-encoded
40
+ semicolon are considered invalid. "
41
+ {:added "1.3.6"
42
+ :go "parseQuery(s)"}
43
+ [^String s])
Original file line number Diff line number Diff line change @@ -7,6 +7,23 @@ import (
7
7
"net/url"
8
8
)
9
9
10
+ var __parse_query__P ProcFn = __parse_query_
11
+ var parse_query_ Proc = Proc {Fn : __parse_query__P , Name : "parse_query_" , Package : "std/url" }
12
+
13
+ func __parse_query_ (_args []Object ) Object {
14
+ _c := len (_args )
15
+ switch {
16
+ case _c == 1 :
17
+ s := ExtractString (_args , 0 )
18
+ _res := parseQuery (s )
19
+ return _res
20
+
21
+ default :
22
+ PanicArity (_c )
23
+ }
24
+ return NIL
25
+ }
26
+
10
27
var __path_escape__P ProcFn = __path_escape_
11
28
var path_escape_ Proc = Proc {Fn : __path_escape__P , Name : "path_escape_" , Package : "std/url" }
12
29
Original file line number Diff line number Diff line change @@ -14,6 +14,15 @@ func InternsOrThunks() {
14
14
}
15
15
urlNamespace .ResetMeta (MakeMeta (nil , `Parses URLs and implements query escaping.` , "1.0" ))
16
16
17
+ urlNamespace .InternVar ("parse-query" , parse_query_ ,
18
+ MakeMeta (
19
+ NewListFrom (NewVectorFrom (MakeSymbol ("s" ))),
20
+ `Parses the URL-encoded query string and returns a map listing the vectors of values specified for each key.
21
+ Always returns a non-nil map containing all the valid query parameters found.
22
+ Query is expected to be a list of key=value settings separated by ampersands. A setting without
23
+ an equals sign is interpreted as a key set to an empty value. Settings containing a non-URL-encoded
24
+ semicolon are considered invalid. ` , "1.3.6" ))
25
+
17
26
urlNamespace .InternVar ("path-escape" , path_escape_ ,
18
27
MakeMeta (
19
28
NewListFrom (NewVectorFrom (MakeSymbol ("s" ))),
Original file line number Diff line number Diff line change @@ -21,3 +21,12 @@ func queryUnescape(s string) string {
21
21
}
22
22
return res
23
23
}
24
+
25
+ func parseQuery (s string ) Object {
26
+ values , _ := url .ParseQuery (s )
27
+ res := EmptyArrayMap ()
28
+ for k , v := range values {
29
+ res .Add (MakeString (k ), MakeStringVector (v ))
30
+ }
31
+ return res
32
+ }
Original file line number Diff line number Diff line change
1
+ (ns joker.test-joker.url
2
+ (:require [joker.test :refer [deftest is]]
3
+ [joker.url :as url]))
4
+
5
+ (deftest parse-query
6
+ (is (= {} (url/parse-query "")))
7
+ (is (= {"q" ["1"]} (url/parse-query "q=1")))
8
+ (is (= {"q" [""]} (url/parse-query "q")))
9
+ (is (= {"foo" ["1"] "bar" ["2" "3"]} (url/parse-query "foo=1&bar=2&bar=3"))))
You can’t perform that action at this time.
0 commit comments