Fixed a previously character changes in WSF_REQUEST (related to safe_filename), and modified the implementation to use inspect

Fixed the request_content_type computation
Cosmetic in REQUEST_RESOURCE_HANDLER_HELPER
This commit is contained in:
Jocelyn Fiat
2011-10-27 16:00:33 +02:00
parent 8e4e7a5084
commit 0d637d478a
3 changed files with 88 additions and 37 deletions

View File

@@ -167,7 +167,7 @@ feature -- Handle responses
Result := Void Result := Void
end end
handle_bad_request_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE ) handle_bad_request_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
local local
h : WSF_HEADER h : WSF_HEADER
do do
@@ -182,7 +182,7 @@ feature -- Handle responses
end end
handle_precondition_fail_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE ) handle_precondition_fail_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
local local
h : WSF_HEADER h : WSF_HEADER
do do
@@ -196,7 +196,7 @@ feature -- Handle responses
res.write_string (a_description) res.write_string (a_description)
end end
handle_internal_server_error (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE ) handle_internal_server_error (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
local local
h : WSF_HEADER h : WSF_HEADER
do do
@@ -224,7 +224,7 @@ feature -- Handle responses
res.write_string (a_description) res.write_string (a_description)
end end
handle_method_not_allowed_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) handle_method_not_allowed_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
h : WSF_HEADER h : WSF_HEADER
do do
@@ -238,7 +238,7 @@ feature -- Handle responses
res.write_string (a_description) res.write_string (a_description)
end end
handle_resource_not_found_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) handle_resource_not_found_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
h : WSF_HEADER h : WSF_HEADER
do do
@@ -253,7 +253,7 @@ feature -- Handle responses
end end
handle_resource_not_modified_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) handle_resource_not_modified_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
h : WSF_HEADER h : WSF_HEADER
do do
@@ -269,7 +269,7 @@ feature -- Handle responses
end end
handle_resource_conflict_response (a_description:STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE) handle_resource_conflict_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
h : WSF_HEADER h : WSF_HEADER
do do

View File

@@ -73,34 +73,39 @@ feature -- Query
local local
s: detachable READABLE_STRING_8 s: detachable READABLE_STRING_8
i,n: INTEGER i,n: INTEGER
l_accept_lst: detachable ARRAYED_LIST [READABLE_STRING_8]
do do
l_accept_lst := accepted_content_types (request)
if attached request.content_type as ct then if attached request.content_type as ct then
Result := ct if l_accept_lst /= Void then
else l_accept_lst.put_front (ct)
if attached accepted_content_types (request) as l_accept_lst then else
from Result := ct
l_accept_lst.start end
until end
l_accept_lst.after or Result /= Void if Result = Void and l_accept_lst /= Void then
loop from
s := l_accept_lst.item l_accept_lst.start
if content_type_supported /= Void then until
from l_accept_lst.after or Result /= Void
i := content_type_supported.lower loop
n := content_type_supported.upper s := l_accept_lst.item
until if content_type_supported /= Void then
i > n or Result /= Void from
loop i := content_type_supported.lower
if content_type_supported[i].same_string (s) then n := content_type_supported.upper
Result := s until
end i > n or Result /= Void
i := i + 1 loop
if content_type_supported[i].same_string (s) then
Result := s
end end
else i := i + 1
Result := s
end end
l_accept_lst.forth else
Result := s
end end
l_accept_lst.forth
end end
end end
end end

View File

@@ -1205,11 +1205,7 @@ feature {NONE} -- Temporary File handling
local local
c: CHARACTER c: CHARACTER
i, n, p: INTEGER i, n, p: INTEGER
l_accentued, l_non_accentued: STRING
do do
l_accentued := "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
l_non_accentued := "AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy"
--| Compute safe filename, to avoid creating impossible filename, or dangerous one --| Compute safe filename, to avoid creating impossible filename, or dangerous one
from from
i := 1 i := 1
@@ -1225,9 +1221,59 @@ feature {NONE} -- Temporary File handling
when 'A' .. 'Z', 'a' .. 'z', '0' .. '9' then when 'A' .. 'Z', 'a' .. 'z', '0' .. '9' then
Result.extend (c) Result.extend (c)
else else
p := l_accentued.index_of (c, 1) inspect c
if p > 0 then when 'À' then Result.extend ('A')
Result.extend (l_non_accentued[p]) when 'Á' then Result.extend ('A')
when 'Â' then Result.extend ('A')
when 'Ã' then Result.extend ('A')
when 'Ä' then Result.extend ('A')
when 'Å' then Result.extend ('A')
when 'Ç' then Result.extend ('C')
when 'È' then Result.extend ('E')
when 'É' then Result.extend ('E')
when 'Ê' then Result.extend ('E')
when 'Ë' then Result.extend ('E')
when 'Ì' then Result.extend ('I')
when 'Í' then Result.extend ('I')
when 'Î' then Result.extend ('I')
when 'Ï' then Result.extend ('I')
when 'Ò' then Result.extend ('O')
when 'Ó' then Result.extend ('O')
when 'Ô' then Result.extend ('O')
when 'Õ' then Result.extend ('O')
when 'Ö' then Result.extend ('O')
when 'Ù' then Result.extend ('U')
when 'Ú' then Result.extend ('U')
when 'Û' then Result.extend ('U')
when 'Ü' then Result.extend ('U')
when 'Ý' then Result.extend ('Y')
when 'à' then Result.extend ('a')
when 'á' then Result.extend ('a')
when 'â' then Result.extend ('a')
when 'ã' then Result.extend ('a')
when 'ä' then Result.extend ('a')
when 'å' then Result.extend ('a')
when 'ç' then Result.extend ('c')
when 'è' then Result.extend ('e')
when 'é' then Result.extend ('e')
when 'ê' then Result.extend ('e')
when 'ë' then Result.extend ('e')
when 'ì' then Result.extend ('i')
when 'í' then Result.extend ('i')
when 'î' then Result.extend ('i')
when 'ï' then Result.extend ('i')
when 'ð' then Result.extend ('o')
when 'ò' then Result.extend ('o')
when 'ó' then Result.extend ('o')
when 'ô' then Result.extend ('o')
when 'õ' then Result.extend ('o')
when 'ö' then Result.extend ('o')
when 'ù' then Result.extend ('u')
when 'ú' then Result.extend ('u')
when 'û' then Result.extend ('u')
when 'ü' then Result.extend ('u')
when 'ý' then Result.extend ('y')
when 'ÿ' then Result.extend ('y')
else else
Result.extend ('-') Result.extend ('-')
end end