From af8e27885874d7e34f7e4ca024bac2299622f516 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 5 Nov 2015 21:24:24 +0100 Subject: [PATCH] Fixed unicode support for uploaded file. Code cleaning. --- .../mime/wsf_multipart_form_data_handler.e | 7 +++-- .../wsf/src/request/value/wsf_uploaded_file.e | 26 +++++++++++++------ .../wsf/src/support/wsf_value_utilities.e | 8 +++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/library/server/wsf/src/mime/wsf_multipart_form_data_handler.e b/library/server/wsf/src/mime/wsf_multipart_form_data_handler.e index e757e19c..50d778a0 100644 --- a/library/server/wsf/src/mime/wsf_multipart_form_data_handler.e +++ b/library/server/wsf/src/mime/wsf_multipart_form_data_handler.e @@ -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 diff --git a/library/server/wsf/src/request/value/wsf_uploaded_file.e b/library/server/wsf/src/request/value/wsf_uploaded_file.e index 5f314df3..d58f53c4 100644 --- a/library/server/wsf/src/request/value/wsf_uploaded_file.e +++ b/library/server/wsf/src/request/value/wsf_uploaded_file.e @@ -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 diff --git a/library/server/wsf/src/support/wsf_value_utilities.e b/library/server/wsf/src/support/wsf_value_utilities.e index 31a87287..60b2bdf3 100644 --- a/library/server/wsf/src/support/wsf_value_utilities.e +++ b/library/server/wsf/src/support/wsf_value_utilities.e @@ -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