Skip to content

Commit

Permalink
remove removal schedule of http_uri and change its implementation to …
Browse files Browse the repository at this point in the history
…uri_string
  • Loading branch information
Whaileee committed Mar 13, 2024
1 parent 16cb401 commit 4ce23cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 72 deletions.
69 changes: 13 additions & 56 deletions lib/inets/src/http_lib/http_uri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,80 +56,37 @@ For more information about URI, see
%%%=========================================================================
%%% API
%%%=========================================================================
reserved() ->
sets:from_list([$;, $:, $@, $&, $=, $+, $,, $/, $?,
$#, $[, $], $<, $>, $\", ${, $}, $|, %"
$\\, $', $^, $%, $ ]).

-doc """
encode(DecodedPart) -> EncodedPart
> #### Warning {: .warning }
>
> Do not use will be removed use `uri_string:quote/1` instead
> Use `uri_string:quote/1` instead
Performes prrcent encoding.
Performs percent encoding.
[](){: #decode }
""".
-doc(#{since => <<"OTP R15B01">>}).
encode(URI) when is_list(URI) ->
Reserved = reserved(),
lists:append([uri_encode(Char, Reserved) || Char <- URI]);
encode(URI) when is_binary(URI) ->
Reserved = reserved(),
<< <<(uri_encode_binary(Char, Reserved))/binary>> || <<Char>> <= URI >>.
-spec encode(Data) -> QuotedData when
Data :: unicode:chardata(),
QuotedData :: unicode:chardata().
encode(Data) ->
uri_string:quote(Data).

-doc """
decode(EncodedPart) -> DecodePart
> #### Warning {: .warning }
>
> Do not use will be removed use `uri_string:unquote/1` instead
> Use `uri_string:unquote/1` instead
Decodes a possibly percent encoded URI part
""".
-doc(#{since => <<"OTP R15B01">>}).
decode(String) when is_list(String) ->
do_decode(String);
decode(String) when is_binary(String) ->
do_decode_binary(String).

do_decode([$%,Hex1,Hex2|Rest]) ->
[hex2dec(Hex1)*16+hex2dec(Hex2)|do_decode(Rest)];
do_decode([First|Rest]) ->
[First|do_decode(Rest)];
do_decode([]) ->
[].

do_decode_binary(<<$%, Hex:2/binary, Rest/bits>>) ->
<<(binary_to_integer(Hex, 16)), (do_decode_binary(Rest))/binary>>;
do_decode_binary(<<First:1/binary, Rest/bits>>) ->
<<First/binary, (do_decode_binary(Rest))/binary>>;
do_decode_binary(<<>>) ->
<<>>.

%%%========================================================================
%%% Internal functions
%%%========================================================================
%% In this version of the function, we no longer need
%% the Scheme argument, but just in case...
uri_encode(Char, Reserved) ->
case sets:is_element(Char, Reserved) of
true ->
[ $% | http_util:integer_to_hexlist(Char)];
false ->
[Char]
end.

uri_encode_binary(Char, Reserved) ->
case sets:is_element(Char, Reserved) of
true ->
<< $%, (integer_to_binary(Char, 16))/binary >>;
false ->
<<Char>>
end.

hex2dec(X) when (X>=$0) andalso (X=<$9) -> X-$0;
hex2dec(X) when (X>=$A) andalso (X=<$F) -> X-$A+10;
hex2dec(X) when (X>=$a) andalso (X=<$f) -> X-$a+10.
-spec decode(QuotedData) -> Data when
QuotedData :: unicode:chardata(),
Data :: unicode:chardata().
decode(QuotedData) ->
uri_string:unquote(QuotedData).
14 changes: 0 additions & 14 deletions lib/stdlib/test/uri_string_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1376,13 +1376,6 @@ quote(_Config) ->

TestQuoteUnquote =
fun(Unquoted) ->
%% case below should be removed when functions used are removed
case Head(Unquoted) =< 127 of
true ->
Unquoted = http_uri:decode(http_uri:encode(Unquoted));
_ ->
ok
end,
Unquoted = uri_string:unquote(uri_string:quote(Unquoted))
end,
[TestQuoteUnquote(U) || #{unquoted := U} <- get_quote_data()],
Expand All @@ -1392,13 +1385,6 @@ quote(_Config) ->
fun(Unquoted, Quoted) ->
Safe = "!$()*", %% characters not encoded by old http_uri:encode
Result = uri_string:quote(Unquoted, Safe),
%% case below should be removed when function used are removed
case Head(Unquoted) =< 127 of
true ->
Result = http_uri:encode(Unquoted);
_ ->
ok
end,
case lists:member(Head(Unquoted), Safe) of
true ->
Unquoted = Result;
Expand Down
4 changes: 2 additions & 2 deletions system/doc/general_info/DEPRECATIONS
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ ssl:cipher_suites/0 since=21 remove=24

http_uri:parse/1 since=23 remove=25
http_uri:parse/2 since=23 remove=25
http_uri:encode/1 since=23 remove=27
http_uri:decode/1 since=23 remove=27
http_uri:encode/1 since=23
http_uri:decode/1 since=23
http_uri:scheme_defaults/0 since=23 remove=25
httpd:parse_query/1 since=23
pg2:_/_ since=23 remove=24
Expand Down

0 comments on commit 4ce23cb

Please sign in to comment.