{ host "www.apple.com" }
{ port 1234 }
{ path "/a/path/relative/path" }
- { query H{ { "a" "b" } } }
+ { query LH{ { "a" "b" } } }
{ anchor "foo" }
}
} [
T{ url
{ path "relative/path" }
- { query H{ { "a" "b" } } }
+ { query LH{ { "a" "b" } } }
{ anchor "foo" }
}
{ host "www.apple.com" }
{ port 1234 }
{ path "/a/path/relative/path" }
- { query H{ { "a" "b" } } }
+ { query LH{ { "a" "b" } } }
{ anchor "foo" }
}
} [
T{ url
{ path "relative/path" }
- { query H{ { "a" "b" } } }
+ { query LH{ { "a" "b" } } }
{ anchor "foo" }
}
<url> "a" "b" set-query-param "b" query-param
] unit-test
+{ t } [
+ URL" http://www.google.com" "foo" "bar" set-query-param
+ query>> linked-assoc?
+] unit-test
+
{ "foo#3" } [ URL" foo" clone 3 >>anchor present ] unit-test
{ "http://www.foo.com/" } [ "http://www.foo.com:80" >url present ] unit-test
{ "git+https" }
[ URL" git+https://google.com/git/factor.git" >url protocol>> ] unit-test
+
+! Params should be rendered in the order in which they are added.
+{ "/?foo=foo&bar=bar&baz=baz" } [
+ URL" /"
+ "foo" "foo" set-query-param
+ "bar" "bar" set-query-param
+ "baz" "baz" set-query-param
+ present
+] unit-test
! Copyright (C) 2008, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs combinators fry hashtables
-io.pathnames io.sockets kernel lexer make math.parser
-namespaces peg.ebnf present sequences splitting strings
-strings.parser urls.encoding vocabs.loader ;
+USING: accessors arrays assocs combinators fry hashtables io.pathnames
+io.sockets kernel lexer linked-assocs make math.parser namespaces
+peg.ebnf present sequences splitting strings strings.parser
+urls.encoding vocabs.loader ;
IN: urls
: query-param ( url key -- value )
swap query>> at ;
-: delete-query-param ( url key -- url )
- over query>> delete-at ;
+: set-or-delete ( val key query -- )
+ pick [ set-at ] [ delete-at drop ] if ;
: set-query-param ( url value key -- url )
- over [
- '[ [ _ _ ] dip ?set-at ] change-query
- ] [
- nip delete-query-param
- ] if ;
+ pick query>> <linked-hash> or [ set-or-delete ] keep >>query ;
ERROR: malformed-port ;
"Official site with news, tour dates, discography, store, community, and more."
} } [ "resource:extra/yahoo/test-results.xml" file>xml parse-yahoo first ] unit-test
-{ URL" http://search.yahooapis.com/WebSearchService/V1/webSearch?similar_ok=1&appid=Factor-search&results=2&query=hi" }
-[ "hi" <search> "Factor-search" >>appid 2 >>results t >>similar-ok query ] unit-test
+{
+ URL" http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=hi&results=2&similar_ok=1"
+} [
+ "hi" <search> "Factor-search" >>appid 2 >>results t >>similar-ok query
+] unit-test