From 1b4b50ee8047afb379860f729292eaf5b1584e12 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Wed, 2 Jul 2014 11:36:43 +0200 Subject: [PATCH] Replace any multiple slash sequence by a single slash character for PATH_INFO. --- .../connectors/nino/src/wgi_nino_handler.e | 34 +++++++++++++++++-- .../implementation/wgi_request_from_table.e | 6 ++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e index 8bbf1b25..86eb66b0 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e @@ -169,7 +169,6 @@ feature -- Request processing if p > 0 then l_path_info.keep_head (p - 1) end - env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") env.force (l_base, "SCRIPT_NAME") else -- This should not happen, this means the `base' is not correctly set. @@ -183,9 +182,11 @@ feature -- Request processing else l_path_info := l_request_uri.string end - env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") env.force ("", "SCRIPT_NAME") end + --| Strip multiple slashes "////abc/def///end////" to "/abc/def/end/" ? + convert_multiple_slashes_to_single (l_path_info) + env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") end callback.process_request (env, a_handler.request_header, a_socket) @@ -213,6 +214,35 @@ feature -- Request processing end end +feature {NONE} -- Implementation + + convert_multiple_slashes_to_single (s: STRING_8) + -- Replace multiple slashes sequence by a single slash character. + local + i,n: INTEGER + do + from + i := 1 + n := s.count + until + i > n + loop + if s[i] = '/' then + -- Remove following slashes '/'. + from + i := i + 1 + until + i > n or s[i] /= '/' + loop + s.remove (i) + n := n - 1 + end + else + i := i + 1 + end + end + end + note copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/server/ewsgi/src/implementation/wgi_request_from_table.e b/library/server/ewsgi/src/implementation/wgi_request_from_table.e index 5274075a..a58eadcb 100644 --- a/library/server/ewsgi/src/implementation/wgi_request_from_table.e +++ b/library/server/ewsgi/src/implementation/wgi_request_from_table.e @@ -387,11 +387,8 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO end l_request_uri := s8 end - --| FIXME: should it strip "////abc/def" to "/abc/def" ? - --| Not sure why this was done before. --- l_request_uri := single_slash_starting_string (l_request_uri) - request_uri := l_request_uri set_meta_string_variable ({WGI_META_NAMES}.request_uri, l_request_uri) + request_uri := l_request_uri end set_orig_path_info (s: READABLE_STRING_8) @@ -418,6 +415,7 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO l_path_info: STRING do l_path_info := path_info + --| Warning --| on IIS: we might have PATH_INFO = /sample.exe/foo/bar --| on apache: PATH_INFO = /foo/bar