Fixed unicode support for uploaded file.

Code cleaning.
This commit is contained in:
2015-11-05 21:24:24 +01:00
parent b6129397a2
commit af8e278858
3 changed files with 28 additions and 13 deletions

View File

@@ -138,10 +138,12 @@ feature {NONE} -- Implementation: Form analyzer
local
n, i,p, b,e: INTEGER
l_name, l_filename, l_content_type: detachable STRING_8
l_unicode_name: READABLE_STRING_32
l_header: detachable STRING_8
l_content: detachable STRING_8
l_line: detachable STRING_8
l_up_file: WSF_UPLOADED_FILE
utf: UTF_CONVERTER
do
from
p := 1
@@ -234,8 +236,9 @@ feature {NONE} -- Implementation: Form analyzer
if l_content_type = Void then
l_content_type := default_content_type
end
create l_up_file.make (l_name, l_filename, l_content_type, l_content.count)
add_value_to_table (l_name, l_up_file, vars)
l_unicode_name := utf.utf_8_string_8_to_string_32 (l_name)
create l_up_file.make (l_unicode_name, utf.utf_8_string_8_to_escaped_string_32 (l_filename), l_content_type, l_content.count)
add_value_to_table (l_unicode_name, l_up_file, vars)
--| `l_up_file' might have a new name
req.save_uploaded_file (l_up_file, l_content)
else

View File

@@ -15,17 +15,27 @@ inherit
end
create
make
make,
make_with_percent_encoded_values
feature {NONE} -- Initialization
make (a_name: READABLE_STRING_8; n: like filename; t: like content_type; s: like size)
make (a_name: READABLE_STRING_GENERAL; a_filename: READABLE_STRING_GENERAL; a_content_type: like content_type; a_size: like size)
do
name := url_decoded_string (a_name)
url_encoded_name := a_name
filename := n
content_type := t
size := s
name := a_name.as_string_32
url_encoded_name := url_encoded_string (a_name)
filename := a_filename.as_string_32
content_type := a_content_type
size := a_size
end
make_with_percent_encoded_values (a_encoded_name: READABLE_STRING_8; a_filename: READABLE_STRING_GENERAL; a_content_type: like content_type; a_size: like size)
do
name := url_decoded_string (a_encoded_name)
url_encoded_name := a_encoded_name
filename := a_filename.as_string_32
content_type := a_content_type
size := a_size
end
feature -- Access
@@ -98,7 +108,7 @@ feature -- Visitor
feature -- Access: Uploaded File
filename: STRING
filename: STRING_32
-- original filename
safe_filename: STRING

View File

@@ -47,9 +47,9 @@ feature -- Smart parameter identification
p,q: INTEGER
tb,ptb: detachable WSF_TABLE
do
--| Check if this is a list format such as choice[] or choice[a] or even choice[a][] or choice[a][b][c]...
l_decoded_name := a_name.as_string_32 --url_encoder.decoded_string (a_name)
l_encoded_name := url_encoder.percent_encoded_string (l_decoded_name)
--| Check if this is a list format such as choice[] or choice[a] or even choice[a][] or choice[a][b][c]...
l_decoded_name := a_name.as_string_32
l_encoded_name := a_value.url_encoded_name
p := l_decoded_name.index_of ({CHARACTER_32}'[', 1)
n := l_decoded_name
if p > 0 then
@@ -136,11 +136,13 @@ feature -- Smart parameter identification
feature -- Factory
new_string_value (a_name: READABLE_STRING_GENERAL; a_value: READABLE_STRING_GENERAL): WSF_STRING
-- New WSF_STRING value built from unicode `a_name' and `a_value'.
do
create Result.make (a_name, a_value)
end
new_string_value_with_percent_encoded_values (a_encoded_name: READABLE_STRING_8; a_encoded_value: READABLE_STRING_8): WSF_STRING
-- New WSF_STRING value built from utf8+percent encoded `a_encoded_name' and `a_encoded_value'.
do
create Result.make_with_percent_encoded_values (a_encoded_name, a_encoded_value)
end