Fix PR14194
This commit is contained in:
parent
7e8ed02704
commit
399e9a25b0
|
@ -90,7 +90,7 @@
|
||||||
[(PATH) 'path]
|
[(PATH) 'path]
|
||||||
[(TOKEN) $1])
|
[(TOKEN) $1])
|
||||||
(rhs [(TOKEN) $1] ; This is legal, but is subsumed by the illegal rule
|
(rhs [(TOKEN) $1] ; This is legal, but is subsumed by the illegal rule
|
||||||
[(QUOTED-STRING) $1]
|
[(QUOTED-STRING) (regexp-replace* (regexp-quote "\\\"") $1 "\"")]
|
||||||
; This is not part of the spec. It is illegal
|
; This is not part of the spec. It is illegal
|
||||||
[(illegal) $1])
|
[(illegal) $1])
|
||||||
(illegal
|
(illegal
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#lang racket
|
#lang racket/base
|
||||||
(require rackunit
|
(require rackunit
|
||||||
|
racket/promise
|
||||||
|
racket/list
|
||||||
net/url
|
net/url
|
||||||
web-server/http/request-structs
|
web-server/http/request-structs
|
||||||
web-server/http/response-structs
|
web-server/http/response-structs
|
||||||
|
@ -53,93 +55,74 @@
|
||||||
(header-value (cookie->header (make-cookie "name" "value" #:secure? #f)))
|
(header-value (cookie->header (make-cookie "name" "value" #:secure? #f)))
|
||||||
#"name=value")))
|
#"name=value")))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(define (reqcs hs)
|
||||||
|
(request-cookies
|
||||||
|
(make-request
|
||||||
|
#"GET" (string->url "http://test.com/foo")
|
||||||
|
hs (delay empty) #f
|
||||||
|
"host" 80 "client")))
|
||||||
|
(define (reqc h)
|
||||||
|
(reqcs (list (make-header #"Cookie" h))))
|
||||||
|
|
||||||
(test-suite
|
(test-suite
|
||||||
"cookie-parse.rkt"
|
"cookie-parse.rkt"
|
||||||
|
|
||||||
|
|
||||||
(test-equal? "None"
|
(test-equal? "None"
|
||||||
(request-cookies
|
(reqcs empty)
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
empty (delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
empty)
|
empty)
|
||||||
|
|
||||||
(test-equal? "Simple"
|
(test-equal? "Simple"
|
||||||
(request-cookies
|
(reqc #"$Version=\"1\"; name=\"value\"")
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie" #"$Version=\"1\"; name=\"value\""))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "$Version" "1" #f #f)
|
(list (make-client-cookie "$Version" "1" #f #f)
|
||||||
(make-client-cookie "name" "value" #f #f)))
|
(make-client-cookie "name" "value" #f #f)))
|
||||||
|
|
||||||
(test-equal? "Path"
|
(test-equal? "Path"
|
||||||
(request-cookies
|
(reqc #"$Version=\"1\"; name=\"value\"; $Path=\"/acme\"")
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie" #"$Version=\"1\"; name=\"value\"; $Path=\"/acme\""))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "$Version" "1" #f #f)
|
(list (make-client-cookie "$Version" "1" #f #f)
|
||||||
(make-client-cookie "name" "value" #f "/acme")))
|
(make-client-cookie "name" "value" #f "/acme")))
|
||||||
|
|
||||||
(test-equal? "Domain"
|
(test-equal? "Domain"
|
||||||
(request-cookies
|
(reqc #"$Version=\"1\"; name=\"value\"; $Domain=\".acme\"")
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie" #"$Version=\"1\"; name=\"value\"; $Domain=\".acme\""))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "$Version" "1" #f #f)
|
(list (make-client-cookie "$Version" "1" #f #f)
|
||||||
(make-client-cookie "name" "value" ".acme" #f)))
|
(make-client-cookie "name" "value" ".acme" #f)))
|
||||||
|
|
||||||
(test-equal? "Multiple"
|
(test-equal? "Multiple"
|
||||||
(request-cookies
|
(reqc #"$Version=\"1\"; key1=\"value1\"; key2=\"value2\"")
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie" #"$Version=\"1\"; key1=\"value1\"; key2=\"value2\""))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "$Version" "1" #f #f)
|
(list (make-client-cookie "$Version" "1" #f #f)
|
||||||
(make-client-cookie "key1" "value1" #f #f)
|
(make-client-cookie "key1" "value1" #f #f)
|
||||||
(make-client-cookie "key2" "value2" #f #f)))
|
(make-client-cookie "key2" "value2" #f #f)))
|
||||||
|
|
||||||
(test-equal? "Multiple w/ paths & domains"
|
(test-equal? "Multiple w/ paths & domains"
|
||||||
(request-cookies
|
(reqc #"$Version=\"1\"; key1=\"value1\"; $Path=\"/acme\"; key2=\"value2\"; $Domain=\".acme\"")
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie" #"$Version=\"1\"; key1=\"value1\"; $Path=\"/acme\"; key2=\"value2\"; $Domain=\".acme\""))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "$Version" "1" #f #f)
|
(list (make-client-cookie "$Version" "1" #f #f)
|
||||||
(make-client-cookie "key1" "value1" #f "/acme")
|
(make-client-cookie "key1" "value1" #f "/acme")
|
||||||
(make-client-cookie "key2" "value2" ".acme" #f)))
|
(make-client-cookie "key2" "value2" ".acme" #f)))
|
||||||
|
|
||||||
(test-equal? "phpBB. PR10689"
|
(test-equal? "phpBB. PR10689"
|
||||||
(request-cookies
|
(reqc #"style_cookie=null; phpbb3_e1p9b_u=54; phpbb3_e1p9b_k=; phpbb3_e1p9b_sid=3fa8d7a7b65fbabcbe9b345861dc079a")
|
||||||
(make-request
|
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie"
|
|
||||||
#"style_cookie=null; phpbb3_e1p9b_u=54; phpbb3_e1p9b_k=; phpbb3_e1p9b_sid=3fa8d7a7b65fbabcbe9b345861dc079a"))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "style_cookie" "null" #f #f)
|
(list (make-client-cookie "style_cookie" "null" #f #f)
|
||||||
(make-client-cookie "phpbb3_e1p9b_u" "54" #f #f)
|
(make-client-cookie "phpbb3_e1p9b_u" "54" #f #f)
|
||||||
(make-client-cookie "phpbb3_e1p9b_k" "" #f #f)
|
(make-client-cookie "phpbb3_e1p9b_k" "" #f #f)
|
||||||
(make-client-cookie "phpbb3_e1p9b_sid" "3fa8d7a7b65fbabcbe9b345861dc079a" #f #f)))
|
(make-client-cookie "phpbb3_e1p9b_sid" "3fa8d7a7b65fbabcbe9b345861dc079a" #f #f)))
|
||||||
|
|
||||||
(test-equal? "Google"
|
(test-equal? "Google"
|
||||||
(request-cookies
|
(reqc #"teaching-order=course;
|
||||||
(make-request
|
__utmz=165257760.1272597702.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)\r\n")
|
||||||
#"GET" (string->url "http://test.com/foo")
|
|
||||||
(list (make-header #"Cookie"
|
|
||||||
#"teaching-order=course;
|
|
||||||
__utmz=165257760.1272597702.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)\r\n"))
|
|
||||||
(delay empty) #f
|
|
||||||
"host" 80 "client"))
|
|
||||||
(list (make-client-cookie "teaching-order" "course" #f #f)
|
(list (make-client-cookie "teaching-order" "course" #f #f)
|
||||||
(make-client-cookie "__utmz" "165257760.1272597702.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)" #f #f)))
|
(make-client-cookie "__utmz" "165257760.1272597702.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)" #f #f)))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(define in "hell\"w\"o")
|
||||||
|
(define out #"id=\"hell\\\"w\\\"o\"")
|
||||||
|
(test-check "quotes (pr14194)" header-equal?
|
||||||
|
(cookie->header (make-cookie "id" in))
|
||||||
|
(make-header #"Set-Cookie" out))
|
||||||
|
(test-equal? "quotes (pr14194)"
|
||||||
|
(reqc out)
|
||||||
|
(list (make-client-cookie "id" in #f #f))))))))
|
||||||
|
|
||||||
)))
|
(module+ test
|
||||||
|
(require rackunit/text-ui)
|
||||||
|
(run-tests cookies-tests))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user