diff --git a/basis/http/http-tests.factor b/basis/http/http-tests.factor index 96320b7d12..6e93d5ee3a 100644 --- a/basis/http/http-tests.factor +++ b/basis/http/http-tests.factor @@ -2,7 +2,7 @@ USING: http http.server http.client tools.test multiline io.streams.string io.encodings.utf8 io.encodings.8-bit io.encodings.binary io.encodings.string kernel arrays splitting sequences assocs io.sockets db db.sqlite continuations urls -hashtables accessors ; +hashtables accessors namespaces ; IN: http.tests [ "text/plain" latin1 ] [ "text/plain" parse-content-type ] unit-test @@ -11,6 +11,12 @@ IN: http.tests [ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test +[ { } ] [ "" parse-cookie ] unit-test +[ { } ] [ "" parse-set-cookie ] unit-test + +! Make sure that totally invalid cookies don't confuse us +[ { } ] [ "hello world; how are you" parse-cookie ] unit-test + : lf>crlf "\n" split "\r\n" join ; STRING: read-request-test-1 @@ -126,6 +132,7 @@ content-type: text/html; charset=UTF-8 ; read-response-test-1' 1array [ + URL" http://localhost/" url set read-response-test-1 lf>crlf [ read-response ] with-string-reader [ write-response ] with-string-writer diff --git a/basis/http/parsers/parsers.factor b/basis/http/parsers/parsers.factor index 8e8e7358d1..d72147b381 100644 --- a/basis/http/parsers/parsers.factor +++ b/basis/http/parsers/parsers.factor @@ -142,16 +142,15 @@ PEG: parse-header-line ( string -- pair ) 'space' , 'attr' , 'space' , - [ "=" token , 'space' , 'value' , ] seq* [ peek ] action - epsilon [ drop f ] action - 2choice , + [ "=" token , 'space' , 'value' , ] seq* [ peek ] action optional , 'space' , ] seq* ; : 'av-pairs' ( -- parser ) 'av-pair' ";" token list-of optional ; -PEG: (parse-set-cookie) ( string -- alist ) 'av-pairs' just ; +PEG: (parse-set-cookie) ( string -- alist ) + 'av-pairs' just [ sift ] action ; : 'cookie-value' ( -- parser ) [ @@ -162,7 +161,10 @@ PEG: (parse-set-cookie) ( string -- alist ) 'av-pairs' just ; 'space' , 'value' , 'space' , - ] seq* ; + ] seq* + [ ";,=" member? not ] satisfy repeat1 [ drop f ] action + 2choice ; PEG: (parse-cookie) ( string -- alist ) - 'cookie-value' [ ";," member? ] satisfy list-of optional just ; + 'cookie-value' [ ";," member? ] satisfy list-of + optional just [ sift ] action ;