diff options
author | Richard Carlsson <richardc@klarna.com> | 2011-08-18 14:32:36 +0200 |
---|---|---|
committer | Richard Carlsson <richardc@klarna.com> | 2011-09-25 20:30:37 +0200 |
commit | 10f76823b8c71ecc84f51bf9f93514d6d25a4a77 (patch) | |
tree | 88d97e390390bc79a294c1385683def21c11cd27 | |
parent | 766d0f0b20d672e90f2672c6b4b9a441497f5ea5 (diff) | |
download | otp-10f76823b8c71ecc84f51bf9f93514d6d25a4a77.tar.gz otp-10f76823b8c71ecc84f51bf9f93514d6d25a4a77.tar.bz2 otp-10f76823b8c71ecc84f51bf9f93514d6d25a4a77.zip |
URI-escape bytes as two hex digits always (reported by Alfonso De Gregorio)
-rw-r--r-- | lib/edoc/src/edoc_lib.erl | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/edoc/src/edoc_lib.erl b/lib/edoc/src/edoc_lib.erl index df929ebf04..7fd8358add 100644 --- a/lib/edoc/src/edoc_lib.erl +++ b/lib/edoc/src/edoc_lib.erl @@ -403,8 +403,13 @@ escape_uri([C | Cs]) -> escape_uri([]) -> []. -escape_byte(C) -> - "%" ++ hex_octet(C). +escape_byte(C) when C >= 0, C =< 255 -> + [$%, hex_digit(C bsr 4), hex_digit(C band 15)]. + +hex_digit(N) when N >= 0, N =< 9 -> + N + $0; +hex_digit(N) when N > 9, N =< 15 -> + N + $a - 10. % utf8([C | Cs]) when C > 16#7f -> % [((C band 16#c0) bsr 6) + 16#c0, C band 16#3f ++ 16#80 | utf8(Cs)]; @@ -413,13 +418,6 @@ escape_byte(C) -> % utf8([]) -> % []. -hex_octet(N) when N =< 9 -> - [$0 + N]; -hex_octet(N) when N > 15 -> - hex_octet(N bsr 4) ++ hex_octet(N band 15); -hex_octet(N) -> - [N - 10 + $a]. - %% Please note that URI are *not* file names. Don't use the stdlib %% 'filename' module for operations on (any parts of) URI. |