blob: 27ea2eb25714db86c671b9a6acdd8aff09b076fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
;;; Weeb --- Web microframework for GNU Guile
;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
;;;
;;; This file is part of Weeb.
;;;
;;; Weeb is free software: you can redistribute it and/or modify it
;;; under the terms of the GNU Affero General Public License as
;;; published by the Free Software Foundation, either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; Weeb is distributed in the hope that it will be useful, but WITHOUT
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
;;; Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public
;;; License along with Weeb. If not, see <https://www.gnu.org/licenses/>.
(use-modules (srfi srfi-1)
(srfi srfi-64)
(weeb request))
(test-runner-current (test-runner-simple))
(test-begin "weeb-request")
(test-group "urldecode"
(test-equal "hello" (urldecode "hello"))
(test-equal "hello world" (urldecode "hello+world"))
(test-equal "hello world" (urldecode "hello%20world"))
(test-equal "!@#$" (urldecode "%21%40%23%24"))
(test-equal "a b c" (urldecode "a+b+c"))
(test-equal "a b c" (urldecode "a%20b%20c"))
(test-equal "" (urldecode ""))
(test-equal "invalid%hex" (urldecode "invalid%hex"))
(test-equal "%" (urldecode "%"))
(test-equal "100%" (urldecode "100%25")))
(test-group "parse-form-urlencoded"
(test-assert
(lset= equal?
'(("key" . "value"))
(parse-form-urlencoded "key=value")))
(test-assert
(lset= equal?
'(("a" . "1") ("b" . "2"))
(parse-form-urlencoded "a=1&b=2")))
(test-assert
(lset= equal?
'(("name" . "John Doe"))
(parse-form-urlencoded "name=John+Doe")))
(test-assert
(lset= equal?
'(("query" . "foo bar"))
(parse-form-urlencoded "query=foo%20bar")))
(test-assert
(lset= equal?
'(("user_id" . "42") ("role" . "admin"))
(parse-form-urlencoded "user_id=42&role=admin")))
(test-assert
(lset= equal?
'(("empty" . ""))
(parse-form-urlencoded "empty=")))
(test-assert
(lset= equal?
'(("foo-bar" . "baz"))
(parse-form-urlencoded "foo-bar=baz")))
(test-assert
(lset= equal?
'(("a" . "1") ("b" . "2") ("c" . "3"))
(parse-form-urlencoded "a=1&b=2&c=3")))
(test-assert
(lset= equal?
'(("foo" . "bar"))
(parse-form-urlencoded "foo=bar"))) ; Verifies (string->symbol key)
(test-assert
(lset= equal?
'()
(parse-form-urlencoded ""))))
(test-group "parse-form-urlencoded arrays"
(test-assert
(lset= equal?
'(("tag" . ("scheme" "guile" "emacs")))
(parse-form-urlencoded "tag=scheme&tag=guile&tag=emacs")))
(test-assert
(lset= equal?
'(("id" . "123") ("items" . ("apple" "orange")))
(parse-form-urlencoded "id=123&items=apple&items=orange")))
(test-assert
(lset= equal?
'(("a" . ("1" "2")) ("b" . ("3" "4")))
(parse-form-urlencoded "a=1&a=2&b=3&b=4")))
(test-assert
(lset= equal?
'(("invitation_code" . "#f")
("edit_code" . "editcode")
("name" . "Test")
("email" . "test")
("rsvp_status" . "attending")
("guest_names" . ("Test" "Also test")))
(parse-form-urlencoded "invitation_code=%23f&edit_code=editcode&name=Test&email=test&rsvp_status=attending&guest_names=Test&guest_names=Also+test")))
(test-assert
(lset= equal?
'(("empty" . ("" "")))
(parse-form-urlencoded "empty=&empty=")))
(test-assert
(lset= equal?
'(("path" . ("/usr/bin" "/bin/bash")))
(parse-form-urlencoded "path=%2Fusr%2Fbin&path=%2Fbin%2Fbash")))
(test-assert
(lset= equal?
'(("x" . ("1" "1" "1" "1")))
(parse-form-urlencoded "x=1&x=1&x=1&x=1")))
(test-assert
(lset= equal?
'(("key" . ""))
(parse-form-urlencoded "key=")))
(test-assert
(lset= equal?
'(("a" . ("1" "2" "3")))
(parse-form-urlencoded "a=1&a=2&a=3")))
(test-assert
(lset= equal?
'(("user" . "admin") ("perms" . ("read" "write" "exec")) ("session" . "active"))
(parse-form-urlencoded "user=admin&perms=read&perms=write&perms=exec&session=active"))))
(test-end)
|
© 2015 - 2026 Jakob L. Kreuze