]> granicus.if.org Git - ejabberd/commitdiff
* src/web/ejabberd_web_admin.erl: Fixed encoding of user names in
authorAlexey Shchepin <alexey@process-one.net>
Tue, 22 Nov 2005 18:25:02 +0000 (18:25 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Tue, 22 Nov 2005 18:25:02 +0000 (18:25 +0000)
URLs

* src/web/ejabberd_http.erl: Added url_encode function from yaws

SVN Revision: 441

ChangeLog
src/web/ejabberd_http.erl
src/web/ejabberd_web_admin.erl

index ff3363fba78c4243f1a2da8c08e9f3e1977fe124..b33cbeb86ef93b9a1a152c6c3ac37067f0334197 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2005-11-22  Alexey Shchepin  <alexey@sevcom.net>
 
+       * src/web/ejabberd_web_admin.erl: Fixed encoding of user names in
+       URLs
+
+       * src/web/ejabberd_http.erl: Added url_encode function from yaws
+
        * src/ejabberd_c2s.erl: Send stream error when connection is
        replaced (thanks to Maxim Ryazanov)
 
index 7b6c65645a400732d6368dc92f2810903634f16e..550f3e0e45191f8b9f6e11b1fbe7553f2d7d97c4 100644 (file)
@@ -13,7 +13,8 @@
 %% External exports
 -export([start/2,
         start_link/2,
-        receive_headers/1]).
+        receive_headers/1,
+        url_encode/1]).
 
 -include("ejabberd.hrl").
 -include("jlib.hrl").
@@ -652,6 +653,46 @@ parse_urlencoded(undefined, _, _, _) ->
     [].
 
 
+url_encode([H|T]) ->
+    if
+       H >= $a, $z >= H ->
+           [H|url_encode(T)];
+       H >= $A, $Z >= H ->
+           [H|url_encode(T)];
+       H >= $0, $9 >= H ->
+           [H|url_encode(T)];
+       H == $_; H == $.; H == $-; H == $/; H == $: -> % FIXME: more..
+           [H|url_encode(T)];
+       true ->
+           case integer_to_hex(H) of
+               [X, Y] ->
+                   [$%, X, Y | url_encode(T)];
+               [X] ->
+                   [$%, $0, X | url_encode(T)]
+           end
+    end;
+
+url_encode([]) ->
+    [].
+
+integer_to_hex(I) ->
+    case catch erlang:integer_to_list(I, 16) of
+       {'EXIT', _} ->
+           old_integer_to_hex(I);
+       Int ->
+           Int
+    end.
+
+
+old_integer_to_hex(I) when I<10 ->
+    integer_to_list(I);
+old_integer_to_hex(I) when I<16 ->
+    [I-10+$A];
+old_integer_to_hex(I) when I>=16 ->
+    N = trunc(I/16),
+    old_integer_to_hex(N) ++ old_integer_to_hex(I rem 16).
+
+
 % The following code is mostly taken from yaws_ssl.erl
 
 parse_request(State, Data) ->
index 0ed317a0cccf80e71e81eff4efb31938e07a7c1d..460b0c28da4d8a4591bc06f21107a6878e539de3 100644 (file)
@@ -1343,8 +1343,11 @@ list_given_users(Users, Prefix, Lang, URLFunc) ->
                                   ?T("Online")
                           end,
                       ?XE("tr",
-                          [?XE("td", [?AC(URLFunc({user, Prefix, User, Server}),
-                                          us_to_list(US))]),
+                          [?XE("td",
+                               [?AC(URLFunc({user, Prefix,
+                                             ejabberd_http:url_encode(User),
+                                             Server}),
+                                    us_to_list(US))]),
                            ?XE("td", FQueueLen),
                            ?XC("td", FLast)])
               end, Users)
@@ -1397,7 +1400,9 @@ list_online_users(Host, _Lang) ->
     SUsers = lists:usort(Users),
     lists:flatmap(
       fun({S, U} = SU) ->
-             [?AC("../user/" ++ U ++ "/", su_to_list(SU)), ?BR]
+             [?AC("../user/" ++ ejabberd_http:url_encode(U) ++ "/",
+                  su_to_list(SU)),
+              ?BR]
       end, SUsers).
 
 user_info(User, Server, Query, Lang) ->