diff options
author | Péter Dimitrov <[email protected]> | 2017-10-18 15:48:04 +0200 |
---|---|---|
committer | Péter Dimitrov <[email protected]> | 2017-10-23 15:53:29 +0200 |
commit | 5fe4c673bb8ee10d0fccadb4da14d7a500c2b8ec (patch) | |
tree | be1512b25cb630b8766a465bc2262356bbaafaca /lib/stdlib/test | |
parent | fd276f4a2a109d19d25cffee54a2c21ee4568085 (diff) | |
download | otp-5fe4c673bb8ee10d0fccadb4da14d7a500c2b8ec.tar.gz otp-5fe4c673bb8ee10d0fccadb4da14d7a500c2b8ec.tar.bz2 otp-5fe4c673bb8ee10d0fccadb4da14d7a500c2b8ec.zip |
stdlib: Implement compose_query and dissect_query
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r-- | lib/stdlib/test/uri_string_SUITE.erl | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/stdlib/test/uri_string_SUITE.erl b/lib/stdlib/test/uri_string_SUITE.erl index 901d38a4da..beb534e023 100644 --- a/lib/stdlib/test/uri_string_SUITE.erl +++ b/lib/stdlib/test/uri_string_SUITE.erl @@ -37,7 +37,9 @@ recompose_query/1, recompose_parse_query/1, recompose_path/1, recompose_parse_path/1, recompose_autogen/1, parse_recompose_autogen/1, - transcode_basic/1, transcode_options/1, transcode_mixed/1, transcode_negative/1 + transcode_basic/1, transcode_options/1, transcode_mixed/1, transcode_negative/1, + compose_query/1, compose_query_negative/1, + dissect_query/1, dissect_query_negative/1 ]). @@ -104,7 +106,11 @@ all() -> transcode_basic, transcode_options, transcode_mixed, - transcode_negative + transcode_negative, + compose_query, + compose_query_negative, + dissect_query, + dissect_query_negative ]. groups() -> @@ -803,5 +809,31 @@ transcode_mixed(_Config) -> transcode_negative(_Config) -> {invalid_input,"foo","BX"} = uri_string:transcode(<<"foo%C3%BXbar"/utf8>>, [{in_encoding, utf8},{out_encoding, utf32}]), - {invalid_input,<<>>,<<"ö">>} = + {invalid_input,unicode,<<"ö">>} = uri_string:transcode("foo%F6bar", [{in_encoding, utf8},{out_encoding, utf8}]). + +compose_query(_Config) -> + [] = uri_string:compose_query([]), + "foo=1&bar=2" = uri_string:compose_query([{<<"foo">>,"1"}, {"bar", "2"}]), + "foo=1&bar=2" = uri_string:compose_query([{"foo","1"}, {"bar", "2"}],[{separator,amp}]), + "foo=1;bar=2" = uri_string:compose_query([{"foo","1"}, {"bar", "2"}],[{separator,semicolon}]), + "foo+bar=1&%C3%B6=2" = uri_string:compose_query([{"foo bar","1"}, {"ö", "2"}]). + +compose_query_negative(_Config) -> + {error,badarg,4} = uri_string:compose_query([{"",4}]). + +dissect_query(_Config) -> + [] = uri_string:dissect_query(""), + [{"foo","1"}, {"bar", "2"}] = uri_string:dissect_query("foo=1&bar=2"), + [{"foo","1"}, {"bar", "2"}] = uri_string:dissect_query("foo=1;bar=2"), + [{"foo","1"}, {"bar", "222"}] = uri_string:dissect_query([<<"foo=1;bar=2">>,"22"]), + [{"foo","ö"}, {"bar", "2"}] = uri_string:dissect_query("foo=%C3%B6&bar=2"). + +dissect_query_negative(_Config) -> + {error,invalid_separator,"≈bar=2"} = + uri_string:dissect_query("foo=1≈bar=2"), + {error,urldecode,"&bar"} = + uri_string:dissect_query("foo1&bar=2"), + {error,urldecode,"%XX%B6"} = uri_string:dissect_query("foo=%XX%B6&bar=2"), + {error,unicode,<<153,182>>} = + uri_string:dissect_query("foo=%99%B6&bar=2"). |