]> gitweb.factorcode.org Git - factor.git/commitdiff
process form names for the developer
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 26 Jan 2009 23:29:50 +0000 (17:29 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 26 Jan 2009 23:29:50 +0000 (17:29 -0600)
basis/mime/multipart/multipart-tests.factor
basis/mime/multipart/multipart.factor

index b6d76c328a3295e6acb8d486fd6caee5d69f4c32..d91e31cca22875a58f119b3a864d72674fbb74b3 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.encodings.ascii io.files io.files.unique kernel
 mime.multipart tools.test io.streams.duplex io multiline
-assocs ;
+assocs accessors ;
 IN: mime.multipart.tests
 
 : upload-separator ( -- seq )
@@ -20,11 +20,16 @@ IN: mime.multipart.tests
 
 [ t ] [
     mime-test-stream [ upload-separator parse-multipart ] with-input-stream
-    "\"file1\"" swap key?
+    "file1" swap key?
 ] unit-test
 
 [ t ] [
     mime-test-stream [ upload-separator parse-multipart ] with-input-stream
-    "\"text1\"" swap key?
+    "file1" swap key?
+] unit-test
+
+[ t ] [
+    mime-test-stream [ upload-separator parse-multipart ] with-input-stream
+    "file1" swap at filename>> "up.txt" =
 ] unit-test
 
index 03a7833a54737d11eb4be437476f85aff1611e5e..e8ba2b8cf44b948518ff1f5b31239a416f9fb547 100755 (executable)
@@ -74,12 +74,24 @@ ERROR: end-of-stream multipart ;
 : empty-name? ( string -- ? )
     { "''" "\"\"" "" f } member? ;
 
+: quote? ( ch -- ? ) "'\"" member? ;
+
+: quoted? ( str -- ? )
+    {
+        [ length 1 > ]
+        [ first quote? ]
+        [ [ first ] [ peek ] bi = ]
+    } 1&& ;
+
+: unquote ( str -- newstr )
+    dup quoted? [ but-last-slice rest-slice >string ] when ;
+
 : save-uploaded-file ( multipart -- )
     dup filename>> empty-name? [
         drop
     ] [
         [ [ header>> ] [ filename>> ] [ temp-file>> ] tri mime-file boa ]
-        [ content-disposition>> "name" swap at ]
+        [ content-disposition>> "name" swap at unquote ]
         [ mime-parts>> set-at ] tri
     ] if ;
 
@@ -88,7 +100,7 @@ ERROR: end-of-stream multipart ;
         drop
     ] [
         [ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ]
-        [ name>> ]
+        [ name>> unquote ]
         [ mime-parts>> set-at ] tri
     ] if ;
 
@@ -112,6 +124,7 @@ ERROR: unknown-content-disposition multipart ;
 
 : parse-form-data ( multipart -- multipart )
     "filename" lookup-disposition [
+        unquote
         >>filename
         [ dump-file ] [ save-uploaded-file ] bi
     ] [