assoc>query should not insert = if value is f. Reported by Chris Double
parent
a0ba66080d
commit
b11e0f6037
|
@ -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
|
||||
|
||||
[ "a=3" ] [ { { "a" 3 } } assoc>query ] unit-test
|
||||
|
||||
[ "a" ] [ { { "a" f } } assoc>query ] unit-test
|
||||
|
||||
[ H{ { "a" f } } ] [ "a" query>assoc ] unit-test
|
|
@ -72,6 +72,15 @@ PRIVATE>
|
|||
] when*
|
||||
] 2keep set-at ;
|
||||
|
||||
: assoc-strings ( assoc -- assoc' )
|
||||
[
|
||||
{
|
||||
{ [ dup not ] [ ] }
|
||||
{ [ dup array? ] [ [ present ] map ] }
|
||||
[ present 1array ]
|
||||
} cond
|
||||
] assoc-map ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: query>assoc ( query -- assoc )
|
||||
|
@ -86,11 +95,8 @@ PRIVATE>
|
|||
|
||||
: assoc>query ( assoc -- str )
|
||||
[
|
||||
dup array? [ [ present ] map ] [ present 1array ] if
|
||||
] assoc-map
|
||||
[
|
||||
[
|
||||
assoc-strings [
|
||||
[ url-encode ] dip
|
||||
[ url-encode "=" glue , ] with each
|
||||
[ [ url-encode "=" glue , ] with each ] [ , ] if*
|
||||
] assoc-each
|
||||
] { } make "&" join ;
|
||||
|
|
|
@ -80,6 +80,15 @@ CONSTANT: urls
|
|||
}
|
||||
"ftp://slava:secret@ftp.kernel.org/"
|
||||
}
|
||||
{
|
||||
T{ url
|
||||
{ protocol "http" }
|
||||
{ host "foo.com" }
|
||||
{ path "/" }
|
||||
{ query H{ { "a" f } } }
|
||||
}
|
||||
"http://foo.com/?a"
|
||||
}
|
||||
}
|
||||
|
||||
urls [
|
||||
|
|
Loading…
Reference in New Issue