process form names for the developer
parent
a1f58d5df1
commit
afdbc6f1d9
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
] [
|
||||
|
|
Loading…
Reference in New Issue