]> granicus.if.org Git - ejabberd/commitdiff
URL path should be tokenized by / and then decoded (EJAB-786).
authorBadlop <badlop@process-one.net>
Wed, 12 Nov 2008 10:03:27 +0000 (10:03 +0000)
committerBadlop <badlop@process-one.net>
Wed, 12 Nov 2008 10:03:27 +0000 (10:03 +0000)
SVN Revision: 1679

ChangeLog
src/web/ejabberd_http.erl

index eda13fb188f8284f1ed5f5c547100070a289d6be..c1d633da9e84f11e1d4a77e8ea3d1c3a14922369 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
 2008-11-12  Badlop  <badlop@process-one.net>
 
        * src/web/ejabberd_http.erl: Include recognized headers in
-       request_headers as atoms, and others as strings (EJAB-778)
+       request_headers as atoms, and others as strings (EJAB-778).
+       URL path should be tokenized by / and then decoded (EJAB-786).
 
        * doc/guide.tex: Improve legibility of mod_irc example config
 
index 821fbb63900f6833f652e1c4eb30ba6a5505b6d5..3d5209d0a1a3e2f122d0dd7c00a7eee6eb41c550 100644 (file)
@@ -327,13 +327,13 @@ process_request(#state{request_method = Method,
        {'EXIT', _} ->
            process_request(false);
        {NPath, Query} ->
+           LPath = [path_decode(NPE) || NPE <- string:tokens(NPath, "/")],
            LQuery = case (catch parse_urlencoded(Query)) of
                         {'EXIT', _Reason} ->
                             [];
                         LQ ->
                             LQ
                     end,
-           LPath = string:tokens(NPath, "/"),
            {ok, IP} =
                case SockMod of
                    gen_tcp ->
@@ -393,7 +393,7 @@ process_request(#state{request_method = Method,
        {'EXIT', _} ->
            process_request(false);
        {NPath, _Query} ->
-           LPath = string:tokens(NPath, "/"),
+           LPath = [path_decode(NPE) || NPE <- string:tokens(NPath, "/")],
            LQuery = case (catch parse_urlencoded(Data)) of
                         {'EXIT', _Reason} ->
                             [];
@@ -599,25 +599,31 @@ crypt(S) when is_binary(S) ->
 %    notice as well as this list of conditions.
 
 
-%% url decode the path and return {Path, QueryPart}
-
+%% @doc Split the URL and return {Path, QueryPart}
 url_decode_q_split(Path) ->
     url_decode_q_split(Path, []).
-
-url_decode_q_split([$%, Hi, Lo | Tail], Ack) ->
-    Hex = hex_to_integer([Hi, Lo]),
-    if Hex  == 0 -> exit(badurl);
-       true -> ok
-    end,
-    url_decode_q_split(Tail, [Hex|Ack]);
 url_decode_q_split([$?|T], Ack) ->
     %% Don't decode the query string here, that is parsed separately.
     {path_norm_reverse(Ack), T};
-url_decode_q_split([H|T], Ack) when H /= 0 -> 
+url_decode_q_split([H|T], Ack) when H /= 0 ->
     url_decode_q_split(T, [H|Ack]);
 url_decode_q_split([], Ack) ->
     {path_norm_reverse(Ack), []}.
 
+%% @doc Decode a part of the URL and return string()
+path_decode(Path) ->
+    path_decode(Path, []).
+path_decode([$%, Hi, Lo | Tail], Ack) ->
+    Hex = hex_to_integer([Hi, Lo]),
+    if Hex  == 0 -> exit(badurl);
+       true -> ok
+    end,
+    path_decode(Tail, [Hex|Ack]);
+path_decode([H|T], Ack) when H /= 0 ->
+    path_decode(T, [H|Ack]);
+path_decode([], Ack) ->
+    lists:reverse(Ack).
+
 path_norm_reverse("/" ++ T) -> start_dir(0, "/", T);
 path_norm_reverse(       T) -> start_dir(0,  "", T).