;;; Weeb --- Web microframework for GNU Guile ;;; Copyright © 2026 Jakob Kreuze ;;; ;;; 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 . (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)