aboutsummaryrefslogtreecommitdiff
path: root/module/web
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-11 20:31:13 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-06-11 23:50:35 +0200
commit90ec10b4c7b94d247c93a4118f325dae9bb25324 (patch)
treef17898284cb60ab4983459001e56865dde390d72 /module/web
parentAdd tests for web-query. (diff)
downloadcalp-90ec10b4c7b94d247c93a4118f325dae9bb25324.tar.gz
calp-90ec10b4c7b94d247c93a4118f325dae9bb25324.tar.xz
Extend web-query to handle keys without values.
Diffstat (limited to 'module/web')
-rw-r--r--module/web/query.scm13
1 files changed, 8 insertions, 5 deletions
diff --git a/module/web/query.scm b/module/web/query.scm
index e5057a24..a70903bc 100644
--- a/module/web/query.scm
+++ b/module/web/query.scm
@@ -8,9 +8,12 @@
(fold (lambda (str list)
;; only split on the first equal.
;; Does HTTP allow multiple equal signs in a data field?
- ;; NOTE that this fails if str lacks an equal sign.
- (define idx (string-index str #\=))
- (define key (uri-decode (substring str 0 idx) encoding: encoding))
- (define val (uri-decode (substring str (1+ idx)) encoding: encoding))
- (cons* (-> key string->symbol symbol->keyword) val list))
+ (let* ((key val
+ (cond ((string-index str #\=)
+ => (lambda (idx)
+ (values (uri-decode (substring str 0 idx) encoding: encoding)
+ (uri-decode (substring str (1+ idx)) encoding: encoding))))
+ (else (let ((v (uri-decode str encoding: encoding)))
+ (values v v))))))
+ (cons* (-> key string->symbol symbol->keyword) val list)))
'() (string-split query-string #\&))))