diff options
author | Péter Dimitrov <[email protected]> | 2018-03-15 10:58:21 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2018-03-15 10:58:21 +0100 |
commit | d171399bb5a0e9f4c6029564ece4fbf89f3c76f8 (patch) | |
tree | 3dd81569f3a398742c1264110976a9b75515f224 /lib | |
parent | eaf20e4f60ba537733752637c7952eb52e225473 (diff) | |
parent | 8df97eea992cf0fd3f1f1fc9f6bbc609949f1355 (diff) | |
download | otp-d171399bb5a0e9f4c6029564ece4fbf89f3c76f8.tar.gz otp-d171399bb5a0e9f4c6029564ece4fbf89f3c76f8.tar.bz2 otp-d171399bb5a0e9f4c6029564ece4fbf89f3c76f8.zip |
Merge pull request #1739 from lucafavatella/http_uri-bin-validate
inets: fix scheme validation in http_uri:parse when binary URI
Diffstat (limited to 'lib')
-rw-r--r-- | lib/inets/src/http_lib/http_uri.erl | 2 | ||||
-rw-r--r-- | lib/inets/test/uri_SUITE.erl | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/inets/src/http_lib/http_uri.erl b/lib/inets/src/http_lib/http_uri.erl index d02913121c..bc588fd390 100644 --- a/lib/inets/src/http_lib/http_uri.erl +++ b/lib/inets/src/http_lib/http_uri.erl @@ -197,7 +197,7 @@ extract_scheme(Str, Opts) -> {value, {scheme_validation_fun, Fun}} when is_function(Fun) -> case Fun(Str) of valid -> - {ok, list_to_atom(http_util:to_lower(Str))}; + {ok, to_atom(http_util:to_lower(Str))}; {error, Error} -> {error, Error} end; diff --git a/lib/inets/test/uri_SUITE.erl b/lib/inets/test/uri_SUITE.erl index f973296af6..8e00e6f565 100644 --- a/lib/inets/test/uri_SUITE.erl +++ b/lib/inets/test/uri_SUITE.erl @@ -52,6 +52,7 @@ all() -> escaped, hexed_query, scheme_validation, + scheme_validation_bin, encode_decode ]. @@ -273,6 +274,26 @@ scheme_validation(Config) when is_list(Config) -> http_uri:parse("https://localhost#fragment", [{scheme_validation_fun, none}]). +scheme_validation_bin(Config) when is_list(Config) -> + {ok, {http,<<>>,<<"localhost">>,80,<<"/">>,<<>>}} = + http_uri:parse(<<"http://localhost#fragment">>), + + ValidationFun = + fun(<<"http">>) -> valid; + (_) -> {error, bad_scheme} + end, + + {ok, {http,<<>>,<<"localhost">>,80,<<"/">>,<<>>}} = + http_uri:parse(<<"http://localhost#fragment">>, + [{scheme_validation_fun, ValidationFun}]), + {error, bad_scheme} = + http_uri:parse(<<"https://localhost#fragment">>, + [{scheme_validation_fun, ValidationFun}]), + %% non-fun scheme_validation_fun works as no option passed + {ok, {https,<<>>,<<"localhost">>,443,<<"/">>,<<>>}} = + http_uri:parse(<<"https://localhost#fragment">>, + [{scheme_validation_fun, none}]). + encode_decode(Config) when is_list(Config) -> ?assertEqual("foo%20bar", http_uri:encode("foo bar")), ?assertEqual(<<"foo%20bar">>, http_uri:encode(<<"foo bar">>)), |