From c7df780c33b85e2f79b6b15519d9e47447520bcc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 20 Jan 2009 15:45:00 -0600 Subject: [PATCH] dont save uploaded variables with no name, swap outputs --- basis/mime/multipart/multipart-tests.factor | 5 +++-- basis/mime/multipart/multipart.factor | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/basis/mime/multipart/multipart-tests.factor b/basis/mime/multipart/multipart-tests.factor index 5d5f1b813a..e1bf0483bc 100644 --- a/basis/mime/multipart/multipart-tests.factor +++ b/basis/mime/multipart/multipart-tests.factor @@ -20,10 +20,11 @@ IN: mime.multipart.tests [ t ] [ mime-test-stream [ upload-separator parse-multipart ] with-input-stream - drop "\"up.txt\"" swap key? + nip "\"up.txt\"" swap key? ] unit-test [ t ] [ mime-test-stream [ upload-separator parse-multipart ] with-input-stream - nip "\"text1\"" swap key? + drop "\"text1\"" swap key? ] unit-test + diff --git a/basis/mime/multipart/multipart.factor b/basis/mime/multipart/multipart.factor index e7985f803d..d61b927cc8 100755 --- a/basis/mime/multipart/multipart.factor +++ b/basis/mime/multipart/multipart.factor @@ -33,8 +33,8 @@ ERROR: bad-header bytes ; : mime-write ( sequence -- ) >byte-array write ; -: parse-headers ( string -- sequence ) - string-lines harvest [ parse-header-line ] map ; +: parse-headers ( string -- hashtable ) + string-lines harvest [ parse-header-line ] map >hashtable ; ERROR: end-of-stream multipart ; @@ -73,11 +73,14 @@ ERROR: end-of-stream multipart ; "\r\n\r\n" dump-string dup "--\r" = [ drop ] [ - parse-headers >hashtable >>header + parse-headers >>header ] if ; +: empty-name? ( string -- ? ) + { "''" "\"\"" "" f } member? ; + : save-uploaded-file ( multipart -- ) - dup filename>> empty? [ + dup filename>> empty-name? [ drop ] [ [ [ header>> ] [ filename>> ] [ temp-file>> ] tri mime-file boa ] @@ -86,9 +89,13 @@ ERROR: end-of-stream multipart ; ] if ; : save-form-variable ( multipart -- ) - [ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ] - [ name>> ] - [ form-variables>> set-at ] tri ; + dup name>> empty-name? [ + drop + ] [ + [ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ] + [ name>> ] + [ form-variables>> set-at ] tri + ] if ; : dump-mime-file ( multipart filename -- multipart ) binary [ @@ -145,6 +152,6 @@ ERROR: no-content-disposition multipart ; read-header dup end-of-stream?>> [ process-header parse-multipart-loop ] unless ; -: parse-multipart ( sep -- uploaded-files form-variables ) +: parse-multipart ( separator -- form-variables uploaded-files ) parse-beginning parse-multipart-loop - [ uploaded-files>> ] [ form-variables>> ] bi ; + [ form-variables>> ] [ uploaded-files>> ] bi ; -- 2.11.4.GIT