aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/src/http_lib
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2011-10-26 12:20:29 +0200
committerMicael Karlberg <[email protected]>2011-10-26 12:20:29 +0200
commit1577983b9b3883b74e3e460ed4f8f6916ffaa3a5 (patch)
tree2986bd8b98369c69d36957c674a965839b6f9d28 /lib/inets/src/http_lib
parent500557baeab33eb1999d34910aa2bb76a0e38f48 (diff)
downloadotp-1577983b9b3883b74e3e460ed4f8f6916ffaa3a5.tar.gz
otp-1577983b9b3883b74e3e460ed4f8f6916ffaa3a5.tar.bz2
otp-1577983b9b3883b74e3e460ed4f8f6916ffaa3a5.zip
Fixed hex-decoding.
OTP-9655
Diffstat (limited to 'lib/inets/src/http_lib')
-rw-r--r--lib/inets/src/http_lib/http_uri.erl33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/inets/src/http_lib/http_uri.erl b/lib/inets/src/http_lib/http_uri.erl
index 3804af60f4..b470fd0b46 100644
--- a/lib/inets/src/http_lib/http_uri.erl
+++ b/lib/inets/src/http_lib/http_uri.erl
@@ -21,7 +21,8 @@
-module(http_uri).
-export([parse/1]).
--export([parse/1, encode/1, decode/1]).
+-export([encode/1, decode/1]).
+
%%%=========================================================================
%%% API
@@ -45,16 +46,33 @@ encode(URI) ->
$\\, $', $^, $%, $ ]),
lists:append(lists:map(fun(Char) -> uri_encode(Char, Reserved) end, URI)).
-decode([$%,Hex1,Hex2|Rest]) ->
- [hex2dec(Hex1)*16+hex2dec(Hex2)|decode(Rest)];
-decode([First|Rest]) ->
- [First|decode(Rest)];
-decode([]) ->
+decode(String) ->
+ try
+ begin
+ do_decode(String)
+ end
+ catch
+ throw:{bad_hex_value, _BadChar} ->
+ %% The string is either badly encoded or a string
+ %% containing a % followed by a non-hex char.
+ %% In any case, return as-is since there is nothing
+ %% we can do...
+ %% Note that the valid hex-chars are: 0-9, a-f and A-F.
+ String
+ end.
+
+do_decode([$%,Hex1,Hex2|Rest]) ->
+ [hex2dec(Hex1)*16+hex2dec(Hex2)|do_decode(Rest)];
+do_decode([First|Rest]) ->
+ [First|do_decode(Rest)];
+do_decode([]) ->
[].
+
%%%========================================================================
%%% Internal functions
%%%========================================================================
+
parse_scheme(AbsURI) ->
case split_uri(AbsURI, ":", {error, no_scheme}, 1, 1) of
{error, no_scheme} ->
@@ -138,4 +156,5 @@ uri_encode(Char, Reserved) ->
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.
+hex2dec(X) when (X>=$a) andalso (X=<$f) -> X-$a+10;
+hex2dec(X) -> throw({bad_hex_value, X}).