aboutsummaryrefslogtreecommitdiff
path: root/cgi-bin/guest_book.cgi
diff options
context:
space:
mode:
authornathan <nathansmith@posteo.com>2025-05-13 01:40:05 -0600
committernathan <nathansmith@posteo.com>2025-05-13 01:40:05 -0600
commitf12d960666655258ef97f1a7058ef9d2891577c9 (patch)
tree60ee703fadbaf7ff08c637af2cf2addc19ad474a /cgi-bin/guest_book.cgi
parente408a73ff81c1270e96e2cffca7a56ac26413c97 (diff)
Query string thing working
Diffstat (limited to 'cgi-bin/guest_book.cgi')
-rwxr-xr-xcgi-bin/guest_book.cgi46
1 files changed, 35 insertions, 11 deletions
diff --git a/cgi-bin/guest_book.cgi b/cgi-bin/guest_book.cgi
index b2baf4f..966093a 100755
--- a/cgi-bin/guest_book.cgi
+++ b/cgi-bin/guest_book.cgi
@@ -7,23 +7,47 @@
(define guest-book-json-file "cgi-bin/guest_book.json")
+(define (decode-hex hex)
+ (string (integer->char
+ (string->number (string-append "#x"
+ hex)))))
+
+(define (format-query-string item)
+ (letrec ((decode-query
+ (lambda (value)
+ (let ((index (string-index value #\%))
+ (value-length (string-length value)))
+ (cond ((and index value-length)
+ (string-append (substring value 0 index)
+ (decode-hex (substring value
+ (+ index 1)
+ (+ index 3)))
+ (cond ((< index (- value-length 3))
+ (decode-query
+ (substring value
+ (+ index 3)
+ value-length)))
+ (else ""))))
+ (else value))))))
+ (decode-query (string-map (lambda (character)
+ (case character
+ ((#\+) #\space)
+ (else character)))
+ item))))
+
;; Progress form data
(define (get-form)
- (let ((query (getenv "QUERY_STRING"))
- (form '()))
+ (let ((query (getenv "QUERY_STRING")))
(cond ((= (string-length query) 0) #f)
(else
- (set! form (string-split query #\&))
- (for-each
- (lambda (item)
- (set! item (string-split item #\=)))
- form)
- form))))
+ (map (lambda (item)
+ (let ((pairs (string-split item #\=)))
+ (set-cdr! pairs (format-query-string (cadr pairs)))
+ pairs))
+ (string-split query #\&))))))
(define (handle-fields)
- (let ((form (get-form)))
- (if form
- (display form))))
+ (display (get-form)))
;; Display a guest in the guest book
(define (display-guest guest)