process form names for the developer
							parent
							
								
									a1f58d5df1
								
							
						
					
					
						commit
						afdbc6f1d9
					
				| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					! See http://factorcode.org/license.txt for BSD license.
 | 
				
			||||||
USING: io.encodings.ascii io.files io.files.unique kernel
 | 
					USING: io.encodings.ascii io.files io.files.unique kernel
 | 
				
			||||||
mime.multipart tools.test io.streams.duplex io multiline
 | 
					mime.multipart tools.test io.streams.duplex io multiline
 | 
				
			||||||
assocs ;
 | 
					assocs accessors ;
 | 
				
			||||||
IN: mime.multipart.tests
 | 
					IN: mime.multipart.tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: upload-separator ( -- seq )
 | 
					: upload-separator ( -- seq )
 | 
				
			||||||
| 
						 | 
					@ -20,11 +20,16 @@ IN: mime.multipart.tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ t ] [
 | 
					[ t ] [
 | 
				
			||||||
    mime-test-stream [ upload-separator parse-multipart ] with-input-stream
 | 
					    mime-test-stream [ upload-separator parse-multipart ] with-input-stream
 | 
				
			||||||
    "\"file1\"" swap key?
 | 
					    "file1" swap key?
 | 
				
			||||||
] unit-test
 | 
					] unit-test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ t ] [
 | 
					[ t ] [
 | 
				
			||||||
    mime-test-stream [ upload-separator parse-multipart ] with-input-stream
 | 
					    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
 | 
					] unit-test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,12 +74,24 @@ ERROR: end-of-stream multipart ;
 | 
				
			||||||
: empty-name? ( string -- ? )
 | 
					: empty-name? ( string -- ? )
 | 
				
			||||||
    { "''" "\"\"" "" f } member? ;
 | 
					    { "''" "\"\"" "" 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 -- )
 | 
					: save-uploaded-file ( multipart -- )
 | 
				
			||||||
    dup filename>> empty-name? [
 | 
					    dup filename>> empty-name? [
 | 
				
			||||||
        drop
 | 
					        drop
 | 
				
			||||||
    ] [
 | 
					    ] [
 | 
				
			||||||
        [ [ header>> ] [ filename>> ] [ temp-file>> ] tri mime-file boa ]
 | 
					        [ [ header>> ] [ filename>> ] [ temp-file>> ] tri mime-file boa ]
 | 
				
			||||||
        [ content-disposition>> "name" swap at ]
 | 
					        [ content-disposition>> "name" swap at unquote ]
 | 
				
			||||||
        [ mime-parts>> set-at ] tri
 | 
					        [ mime-parts>> set-at ] tri
 | 
				
			||||||
    ] if ;
 | 
					    ] if ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,7 +100,7 @@ ERROR: end-of-stream multipart ;
 | 
				
			||||||
        drop
 | 
					        drop
 | 
				
			||||||
    ] [
 | 
					    ] [
 | 
				
			||||||
        [ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ]
 | 
					        [ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ]
 | 
				
			||||||
        [ name>> ]
 | 
					        [ name>> unquote ]
 | 
				
			||||||
        [ mime-parts>> set-at ] tri
 | 
					        [ mime-parts>> set-at ] tri
 | 
				
			||||||
    ] if ;
 | 
					    ] if ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,6 +124,7 @@ ERROR: unknown-content-disposition multipart ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: parse-form-data ( multipart -- multipart )
 | 
					: parse-form-data ( multipart -- multipart )
 | 
				
			||||||
    "filename" lookup-disposition [
 | 
					    "filename" lookup-disposition [
 | 
				
			||||||
 | 
					        unquote
 | 
				
			||||||
        >>filename
 | 
					        >>filename
 | 
				
			||||||
        [ dump-file ] [ save-uploaded-file ] bi
 | 
					        [ dump-file ] [ save-uploaded-file ] bi
 | 
				
			||||||
    ] [
 | 
					    ] [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue