From 2899c848e7ef82cd03b3a65b48ed3e74c1caa4a0 Mon Sep 17 00:00:00 2001 From: Ian Price Date: Fri, 9 Sep 2011 20:05:13 +0100 Subject: [PATCH 2/2] Allow unquoted Etags. * module/web/http.scm (parse-qstring): If qstring doesn't start with a #\", then treat as opaque. * test-suite/tests/web-http.test("response headers"): Add test. --- module/web/http.scm | 34 ++++++++++++++++++---------------- test-suite/tests/web-http.test | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/module/web/http.scm b/module/web/http.scm index 70db813..82c1f87 100644 --- a/module/web/http.scm +++ b/module/web/http.scm @@ -317,22 +317,24 @@ ordered alist." (define* (parse-qstring str #:optional (start 0) (end (trim-whitespace str start)) #:key incremental?) - (if (and (< start end) (eqv? (string-ref str start) #\")) - (let lp ((i (1+ start)) (qi 0) (escapes '())) - (if (< i end) - (case (string-ref str i) - ((#\\) - (lp (+ i 2) (1+ qi) (cons qi escapes))) - ((#\") - (let ((out (collect-escaped-string str (1+ start) qi escapes))) - (if incremental? - (values out (1+ i)) - (if (= (1+ i) end) - out - (bad-header-component 'qstring str))))) - (else - (lp (1+ i) (1+ qi) escapes))) - (bad-header-component 'qstring str))) + (if (and (< start end)) + (if (eqv? (string-ref str start) #\") + (let lp ((i (1+ start)) (qi 0) (escapes '())) + (if (< i end) + (case (string-ref str i) + ((#\\) + (lp (+ i 2) (1+ qi) (cons qi escapes))) + ((#\") + (let ((out (collect-escaped-string str (1+ start) qi escapes))) + (if incremental? + (values out (1+ i)) + (if (= (1+ i) end) + out + (bad-header-component 'qstring str))))) + (else + (lp (1+ i) (1+ qi) escapes))) + (bad-header-component 'qstring str))) + (parse-opaque-string (substring str start end))) (bad-header-component 'qstring str))) (define (write-list l port write-item delim) diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test index e4d6efb..4591cd1 100644 --- a/test-suite/tests/web-http.test +++ b/test-suite/tests/web-http.test @@ -199,6 +199,7 @@ (pass-if-parse accept-ranges "foo,bar" '(foo bar)) (pass-if-parse age "30" 30) (pass-if-parse etag "\"foo\"" '("foo" . #t)) + (pass-if-parse etag "1315389780000" '("1315389780000" . #t)) (pass-if-parse etag "W/\"foo\"" '("foo" . #f)) (pass-if-parse location "http://other-place" (build-uri 'http #:host "other-place")) -- 1.7.6