assoc>query should not insert = if value is f. Reported by Chris Double

db4
Slava Pestov 2009-04-10 04:01:59 -05:00
parent a0ba66080d
commit b11e0f6037
3 changed files with 24 additions and 5 deletions

View File

@ -26,3 +26,7 @@ USING: urls.encoding tools.test arrays kernel assocs present accessors ;
[ H{ { "text" "hello world" } } ] [ "text=hello+world" query>assoc ] unit-test [ H{ { "text" "hello world" } } ] [ "text=hello+world" query>assoc ] unit-test
[ "a=3" ] [ { { "a" 3 } } assoc>query ] unit-test [ "a=3" ] [ { { "a" 3 } } assoc>query ] unit-test
[ "a" ] [ { { "a" f } } assoc>query ] unit-test
[ H{ { "a" f } } ] [ "a" query>assoc ] unit-test

View File

@ -72,6 +72,15 @@ PRIVATE>
] when* ] when*
] 2keep set-at ; ] 2keep set-at ;
: assoc-strings ( assoc -- assoc' )
[
{
{ [ dup not ] [ ] }
{ [ dup array? ] [ [ present ] map ] }
[ present 1array ]
} cond
] assoc-map ;
PRIVATE> PRIVATE>
: query>assoc ( query -- assoc ) : query>assoc ( query -- assoc )
@ -86,11 +95,8 @@ PRIVATE>
: assoc>query ( assoc -- str ) : assoc>query ( assoc -- str )
[ [
dup array? [ [ present ] map ] [ present 1array ] if assoc-strings [
] assoc-map
[
[
[ url-encode ] dip [ url-encode ] dip
[ url-encode "=" glue , ] with each [ [ url-encode "=" glue , ] with each ] [ , ] if*
] assoc-each ] assoc-each
] { } make "&" join ; ] { } make "&" join ;

View File

@ -80,6 +80,15 @@ CONSTANT: urls
} }
"ftp://slava:secret@ftp.kernel.org/" "ftp://slava:secret@ftp.kernel.org/"
} }
{
T{ url
{ protocol "http" }
{ host "foo.com" }
{ path "/" }
{ query H{ { "a" f } } }
}
"http://foo.com/?a"
}
} }
urls [ urls [