]> gitweb.factorcode.org Git - factor.git/commitdiff
dont save uploaded variables with no name, swap outputs
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 20 Jan 2009 21:45:00 +0000 (15:45 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 20 Jan 2009 21:45:00 +0000 (15:45 -0600)
basis/mime/multipart/multipart-tests.factor
basis/mime/multipart/multipart.factor

index 5d5f1b813a353c57737b7c92a9e4e342bae7ec78..e1bf0483bcff84cd44afec52cf6e51f035ff3577 100644 (file)
@@ -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
+
index e7985f803d025a6540dbbd5388289c5859421196..d61b927cc829b992fadecdc57dc6bce9d7c18b3c 100755 (executable)
@@ -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 <file-writer> [
@@ -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 )
     <multipart> parse-beginning parse-multipart-loop
-    [ uploaded-files>> ] [ form-variables>> ] bi ;
+    [ form-variables>> ] [ uploaded-files>> ] bi ;