Fixing cookie regex

This commit is contained in:
Jay McCarthy 2010-04-27 08:48:07 -06:00
parent 67d804af62
commit 96a3f47ea0
2 changed files with 19 additions and 8 deletions

View File

@ -255,7 +255,7 @@
;; appear as a block to be legal, and " may only appear as \" ;; appear as a block to be legal, and " may only appear as \"
(define (rfc2068:quoted-string? s) (define (rfc2068:quoted-string? s)
(and (regexp-match? (and (regexp-match?
#rx"^\"([^\"#\u0000-#\u001F]| |#\return#\newline|#\tab|\\\\\")*\"$" #rx"^\"([^\"\u0000-\u001F]| |\r\n|\t|\\\\\")*\"$"
s) s)
s)) s))

View File

@ -19,12 +19,12 @@
(syntax-rules () (syntax-rules ()
[(o/* x) x] [(o/* x) x]
[(o/* x f g ...) (f (o/* x g ...))])) [(o/* x f g ...) (f (o/* x g ...))]))
(define (tests) (define (tests)
;; test the most basic functionality ;; test the most basic functionality
(cookie-test (λ (x) x) "a=b; Version=1") (cookie-test (λ (x) x) "a=b; Version=1")
;; test each modifier individually ;; test each modifier individually
(cookie-test (RC cookie:add-comment "set+a+to+b") (cookie-test (RC cookie:add-comment "set+a+to+b")
"a=b; Comment=set+a+to+b; Version=1") "a=b; Comment=set+a+to+b; Version=1")
@ -54,7 +54,7 @@
"a=b; Version=1") "a=b; Version=1")
(cookie-test (RC cookie:version 12) (cookie-test (RC cookie:version 12)
"a=b; Version=12") "a=b; Version=12")
;; test combinations ;; test combinations
(cookie-test (o (RC cookie:add-comment "set+a+to+b") (cookie-test (o (RC cookie:add-comment "set+a+to+b")
(RC cookie:add-domain ".example.net")) (RC cookie:add-domain ".example.net"))
@ -66,7 +66,7 @@
(RC cookie:version 10) (RC cookie:version 10)
(RC cookie:add-max-age 20)) (RC cookie:add-max-age 20))
"a=b; Max-Age=20; Path=\"/whatever/wherever/\"; Version=10") "a=b; Max-Age=20; Path=\"/whatever/wherever/\"; Version=10")
;; test error cases ;; test error cases
(let () (let ()
(define-syntax cookie-error-test (define-syntax cookie-error-test
@ -78,7 +78,18 @@
(cookie-error-test (RC cookie:add-domain "doesntstartwithadot.example.com")) (cookie-error-test (RC cookie:add-domain "doesntstartwithadot.example.com"))
(cookie-error-test (RC cookie:add-domain "bad domain.com")) (cookie-error-test (RC cookie:add-domain "bad domain.com"))
(cookie-error-test (RC cookie:add-domain ".bad-domain;com"))) (cookie-error-test (RC cookie:add-domain ".bad-domain;com")))
; cookie value
(test
(cookie-value? "value")
(cookie-value? "(")
(cookie-value? "!")
(cookie-value? ")")
(cookie-value? ")!")
(cookie-value? "(!")
(cookie-value? "(!)")
(cookie-value? "!)"))
) )
(test do (tests))) (test do (tests)))