From 01cd03b8430f1d1f45efb04f9b3663f14ee35087 Mon Sep 17 00:00:00 2001 From: Omri Rotem Date: Sun, 29 Oct 2017 13:57:33 +0200 Subject: [PATCH 1/4] fix query:flodl/3 - account for more than 2 params --- src/uri.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/uri.erl b/src/uri.erl index a940ed9..ad097a8 100644 --- a/src/uri.erl +++ b/src/uri.erl @@ -189,6 +189,9 @@ query_foldl(F, Init, #uri{q = Query}) -> query_foldl(F, Init, Query); query_foldl(F, Init, Query) when erlang:is_binary(Query) -> + BinaryQuery = erlang:iolist_to_binary(Query), + SplitQuery = binary:split(BinaryQuery, <<"&">>, [global]), + lists:foldl(fun (Part, Acc) -> case binary:split(Part, <<"=">>) of [Key, Value] -> @@ -198,7 +201,7 @@ query_foldl(F, Init, Query) [Key] -> F({unquote(Key), true}, Acc) end - end, Init, binary:split(erlang:iolist_to_binary(Query), <<"&">>)); + end, Init, SplitQuery); query_foldl(F, Init, Query) when erlang:is_list(Query) -> lists:foldl(F, Init, Query). @@ -688,6 +691,8 @@ query_to_proplist_test() -> ?assertMatch([{<<"a">>, <<"b">>}], query_to_proplist(<<"a=b&">>)), ?assertMatch([{<<"a">>, <<>>}], query_to_proplist(<<"a=">>)), ?assertMatch([{<<"a">>, true}, {<<"b">>, <<"c">>}], query_to_proplist(<<"a&b=c">>)), + ?assertMatch([{<<"b">>, <<"c">>}, {<<"d">>, <<"g">>}, {<<"a">>, true}], + query_to_proplist(<<"b=c&d=g&a">>)), ?assertMatch([{<<"a&b">>, <<"!t=f">>}], query_to_proplist(<<"a%26b=!t%3Df">>)). to_query_test() -> From 080b050f451617983efc122a245ffbc67777696d Mon Sep 17 00:00:00 2001 From: Omri Rotem Date: Sun, 1 Apr 2018 13:32:20 +0300 Subject: [PATCH 2/4] remove rebar_vsn_plugin dependancy --- rebar.config | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/rebar.config b/rebar.config index 8304a7f..dbf48fb 100644 --- a/rebar.config +++ b/rebar.config @@ -1,13 +1,3 @@ -%% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- -%% Dependencies ================================================================ -{deps, [{rebar_vsn_plugin, ".*", - {git, "https://github.com/erlware/rebar_vsn_plugin.git", - {branch, "master"}}}]}. - - -%% Rebar Plugins ============================================================== -{plugins, [rebar_vsn_plugin]}. - %% Compiler Options ============================================================ {erl_opts, [debug_info, warnings_as_errors, inline]}. From b8fe9a54d969b36078e857fc5a9355caa8bf898c Mon Sep 17 00:00:00 2001 From: Omri Rotem Date: Sun, 1 Apr 2018 13:41:58 +0300 Subject: [PATCH 3/4] remove export_all compile flag --- src/uri.erl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/uri.erl b/src/uri.erl index ad097a8..fa17fc0 100644 --- a/src/uri.erl +++ b/src/uri.erl @@ -23,8 +23,6 @@ %%% uri's, but that could/should change in the future. -module(uri). --compile(export_all). - -export([new/7, from_string/1, from_http_1_1/3, to_string/1, query_foldl/3, query_to_proplist/1, From 06c8112a8e46090d5f4a58ea47960c5fe368866e Mon Sep 17 00:00:00 2001 From: Omri Rotem Date: Mon, 2 Apr 2018 13:24:33 +0300 Subject: [PATCH 4/4] cope with uris that miss the path part --- src/uri.erl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/uri.erl b/src/uri.erl index fa17fc0..a092e64 100644 --- a/src/uri.erl +++ b/src/uri.erl @@ -399,12 +399,14 @@ parse_scheme(<>, Acc) -> parse_scheme(Rest, <>). parse_authority(<<$/, $/, Uri/binary>>) -> - parse_authority(Uri, <<"">>); + parse_authority(Uri, <<>>); parse_authority(Uri) -> - Uri. + {Uri, <<>>}. parse_authority(<<$/, Rest/binary>>, Acc) -> {Acc, <<$/, Rest/binary>>}; +parse_authority(<<$?, Rest/binary>>, Acc) -> + {Acc, <<$?, Rest/binary>>}; parse_authority(<<>>, Acc) -> {Acc, <<>>}; parse_authority(<>, Acc) -> @@ -662,7 +664,7 @@ parse_scheme_test() -> parse_authority_test() -> ?assertMatch({<<"test.com">>, <<"/here">>}, parse_authority(<<"//test.com/here">>)), ?assertMatch({<<"test.com">>, <<"">>}, parse_authority(<<"//test.com">>)), - ?assertMatch(<<"/test">>, parse_authority(<<"/test">>)). + ?assertMatch({<<"/test">>, <<>>}, parse_authority(<<"/test">>)). parse_user_info_test() -> ?assertMatch({<<"user">>, <<"test.com">>}, parse_user_info(<<"user@test.com">>)),