Merge branch 'fix_cgi_value' of github.com:jocelyn/EWF
This commit is contained in:
@@ -25,11 +25,8 @@ feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: READABLE_STRING_8; a_string: READABLE_STRING_8)
|
||||
do
|
||||
name := url_decoded_string (a_name)
|
||||
value := url_decoded_string (a_string)
|
||||
|
||||
url_encoded_name := a_name
|
||||
url_encoded_value := a_string
|
||||
url_encoded_name := utf_8_percent_encoded_string (a_name)
|
||||
url_encoded_value := utf_8_percent_encoded_string (a_string)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -38,11 +35,31 @@ feature -- Access
|
||||
-- <Precursor>
|
||||
--| Note that the value might be html encoded as well
|
||||
--| this is the application responsibility to html decode it
|
||||
local
|
||||
v: like internal_name
|
||||
do
|
||||
v := internal_name
|
||||
if v = Void then
|
||||
v := url_decoded_string (url_encoded_name)
|
||||
internal_name := v
|
||||
end
|
||||
Result := v
|
||||
end
|
||||
|
||||
value: READABLE_STRING_32
|
||||
-- <Precursor>
|
||||
--| Note that the value might be html encoded as well
|
||||
--| this is the application responsibility to html decode it
|
||||
local
|
||||
v: like internal_value
|
||||
do
|
||||
v := internal_value
|
||||
if v = Void then
|
||||
v := url_decoded_string (url_encoded_value)
|
||||
internal_value := v
|
||||
end
|
||||
Result := v
|
||||
end
|
||||
|
||||
url_encoded_name: READABLE_STRING_8
|
||||
-- URL encoded string of `name'.
|
||||
@@ -50,6 +67,14 @@ feature -- Access
|
||||
url_encoded_value: READABLE_STRING_8
|
||||
-- URL encoded string of `value'.
|
||||
|
||||
feature {NONE} -- Access: internals
|
||||
|
||||
internal_name: detachable like name
|
||||
-- Cached value of `name'.
|
||||
|
||||
internal_value: detachable like value
|
||||
-- Cached value of `value'.
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
integer_value: INTEGER
|
||||
@@ -81,7 +106,7 @@ feature -- Element change
|
||||
|
||||
change_name (a_name: like name)
|
||||
do
|
||||
name := url_decoded_string (a_name)
|
||||
internal_name := Void
|
||||
url_encoded_name := a_name
|
||||
ensure then
|
||||
a_name.same_string (url_encoded_name)
|
||||
@@ -122,8 +147,89 @@ feature -- Visitor
|
||||
vis.process_string (Current)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
utf_8_percent_encoded_string (s: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Percent-encode the UTF-8 sequence characters from UTF-8 encoded `s' and
|
||||
-- return the Result.
|
||||
local
|
||||
s8: STRING_8
|
||||
i, n, nb: INTEGER
|
||||
do
|
||||
-- First check if there are such UTF-8 character
|
||||
-- If it has, convert them and return a new object as Result
|
||||
-- otherwise return `s' directly to avoid creating a new object
|
||||
from
|
||||
i := 1
|
||||
n := s.count
|
||||
nb := 0
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
if s.code (i) > 0x7F then -- >= 128
|
||||
nb := nb + 1
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
if nb > 0 then
|
||||
create s8.make (s.count + nb * 3)
|
||||
utf_8_string_8_into_percent_encoded_string_8 (s, s8)
|
||||
Result := s8
|
||||
else
|
||||
Result := s
|
||||
end
|
||||
end
|
||||
|
||||
utf_8_string_8_into_percent_encoded_string_8 (s: READABLE_STRING_8; a_result: STRING_8)
|
||||
-- Copy STRING_32 corresponding to UTF-8 sequence `s' appended into `a_result'.
|
||||
local
|
||||
i: INTEGER
|
||||
n: INTEGER
|
||||
c: NATURAL_32
|
||||
do
|
||||
from
|
||||
n := s.count
|
||||
a_result.grow (a_result.count + n)
|
||||
until
|
||||
i >= n
|
||||
loop
|
||||
i := i + 1
|
||||
c := s.code (i)
|
||||
if c <= 0x7F then
|
||||
-- 0xxxxxxx
|
||||
a_result.append_code (c)
|
||||
elseif c <= 0xDF then
|
||||
-- 110xxxxx 10xxxxxx
|
||||
url_encoder.append_percent_encoded_character_code_to (c, a_result)
|
||||
i := i + 1
|
||||
if i <= n then
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
end
|
||||
elseif c <= 0xEF then
|
||||
-- 1110xxxx 10xxxxxx 10xxxxxx
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
i := i + 2
|
||||
if i <= n then
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i - 1), a_result)
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
end
|
||||
elseif c <= 0xF7 then
|
||||
-- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
i := i + 3
|
||||
if i <= n then
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i - 2), a_result)
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i - 1), a_result)
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
end
|
||||
else
|
||||
a_result.append_code (c)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -71,6 +71,7 @@ feature -- Query
|
||||
string_representation: STRING_32
|
||||
-- String representation of Current
|
||||
-- if possible
|
||||
-- note: unicode value.
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -127,7 +128,7 @@ feature -- Visitor
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -20,8 +20,8 @@ note
|
||||
About https support: `is_https' indicates if the request is made through an https connection or not.
|
||||
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
date: "$Date: 2014-05-14 16:52:42 +0200 (mer., 14 mai 2014) $"
|
||||
revision: "$Revision: 95057 $"
|
||||
|
||||
class
|
||||
WSF_REQUEST
|
||||
@@ -87,18 +87,19 @@ feature {NONE} -- Initialization
|
||||
local
|
||||
s8: detachable READABLE_STRING_8
|
||||
req: WGI_REQUEST
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
init_mime_handlers
|
||||
req := wgi_request
|
||||
|
||||
--| Content-Length
|
||||
--| Content-Length
|
||||
if attached content_length as s and then s.is_natural_64 then
|
||||
content_length_value := s.to_natural_64
|
||||
else
|
||||
content_length_value := 0
|
||||
end
|
||||
|
||||
-- Content-Type
|
||||
--| Content-Type
|
||||
s8 := req.content_type
|
||||
if s8 /= Void then
|
||||
create content_type.make_from_string (s8)
|
||||
@@ -106,18 +107,11 @@ feature {NONE} -- Initialization
|
||||
content_type := Void
|
||||
end
|
||||
|
||||
--| Request Methods
|
||||
--| Request Methods
|
||||
request_method := req.request_method
|
||||
|
||||
--| PATH_INFO
|
||||
percent_encoded_path_info := req.path_info
|
||||
path_info := url_decoded_string (req.path_info)
|
||||
|
||||
--| PATH_TRANSLATED
|
||||
s8 := req.path_translated
|
||||
if s8 /= Void then
|
||||
path_translated := url_decoded_string (s8)
|
||||
end
|
||||
--| PATH_INFO
|
||||
path_info := utf.utf_8_string_8_to_string_32 (req.path_info)
|
||||
|
||||
--| Here one can set its own environment entries if needed
|
||||
if meta_variable ({WSF_META_NAMES}.request_time) = Void then
|
||||
@@ -139,9 +133,19 @@ feature {NONE} -- Initialization
|
||||
end
|
||||
end
|
||||
|
||||
feature {WSF_REQUEST_EXPORTER} -- Restricted Access
|
||||
|
||||
wgi_request: WGI_REQUEST
|
||||
-- Associated WGI request
|
||||
|
||||
cgi_variables: WGI_REQUEST_CGI_VARIABLES
|
||||
-- Object containing the CGI variables
|
||||
--| mainly for debugging purpose.
|
||||
--| note: a new instance is created on each call!
|
||||
do
|
||||
Result := wgi_request.cgi_variables
|
||||
end
|
||||
|
||||
feature -- Destroy
|
||||
|
||||
destroy
|
||||
@@ -166,9 +170,9 @@ feature -- Destroy
|
||||
form_parameters_table.wipe_out
|
||||
mime_handlers := Void
|
||||
path_info := empty_string_32
|
||||
internal_percent_encoded_path_info := Void
|
||||
path_parameters_source := Void
|
||||
path_parameters_table := Void
|
||||
path_translated := Void
|
||||
raw_input_data := Void
|
||||
raw_input_data_recorded := False
|
||||
request_method := empty_string_8
|
||||
@@ -612,6 +616,12 @@ feature -- Helpers: global variables
|
||||
|
||||
feature -- Execution variables
|
||||
|
||||
execution_variables: TABLE_ITERABLE [detachable ANY, READABLE_STRING_GENERAL]
|
||||
-- Execution variables values.
|
||||
do
|
||||
Result := execution_variables_table
|
||||
end
|
||||
|
||||
has_execution_variable (a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Has execution variable related to `a_name'?
|
||||
require
|
||||
@@ -829,19 +839,52 @@ feature -- Access: CGI meta parameters - 1.1
|
||||
end
|
||||
|
||||
percent_encoded_path_info: READABLE_STRING_8
|
||||
-- Non decoded PATH_INFO value from CGI.
|
||||
-- Percent encoded PATH_INFO value from CGI.
|
||||
-- See `path_info' for the related percent decoded value.
|
||||
--| This value should be used by component dealing only with ASCII path
|
||||
--| this value is not always available, so it requires to be computed.
|
||||
local
|
||||
l_result: like internal_percent_encoded_path_info
|
||||
r: READABLE_STRING_8
|
||||
i: INTEGER
|
||||
do
|
||||
l_result := internal_percent_encoded_path_info
|
||||
if l_result = Void then
|
||||
r := request_uri
|
||||
i := r.index_of ('?', 1)
|
||||
if i > 0 then
|
||||
l_result := r.substring (1, i - 1)
|
||||
else
|
||||
l_result := r.string
|
||||
end
|
||||
if attached script_name as s then
|
||||
if l_result.starts_with (s) then
|
||||
l_result := l_result.substring (s.count + 1, l_result.count)
|
||||
end
|
||||
end
|
||||
internal_percent_encoded_path_info := l_result
|
||||
end
|
||||
Result := l_result
|
||||
end
|
||||
|
||||
utf_8_path_info: READABLE_STRING_8
|
||||
-- UTF-8 encoded value for PATH_INFO.
|
||||
-- See `path_info' for extended description.
|
||||
do
|
||||
Result := wgi_request.path_info
|
||||
end
|
||||
|
||||
path_info: READABLE_STRING_32
|
||||
-- The PATH_INFO metavariable specifies a path to be interpreted
|
||||
-- by the CGI script. It identifies the resource or sub-resource
|
||||
-- to be returned by the CGI script, and it is derived from the
|
||||
-- portion of the URI path following the script name but
|
||||
-- preceding any query data. The syntax and semantics are similar
|
||||
-- to a decoded HTTP URL 'path' token (defined in RFC 2396 [4]),
|
||||
-- with the exception that a PATH_INFO of "/" represents a single
|
||||
-- void path segment.
|
||||
-- preceding any query data.
|
||||
-- Unlike a URI path, the PATH_INFO is not URL-encoded, and cannot
|
||||
-- contain path-segment parameters.
|
||||
-- The syntax and semantics are similar to a decoded HTTP URL 'path' token
|
||||
-- (defined in RFC 2396 [4]), with the exception that a PATH_INFO of "/"
|
||||
-- represents a single void path segment.
|
||||
--
|
||||
-- PATH_INFO = "" | ( "/" path )
|
||||
-- path = segment *( "/" segment )
|
||||
@@ -862,9 +905,10 @@ feature -- Access: CGI meta parameters - 1.1
|
||||
-- preserve the case of the PATH_INFO element of the URI when
|
||||
-- making it available to scripts.
|
||||
--
|
||||
-- See `percent_encoded_path_info' to get the original non decoded path info.
|
||||
-- Note: this is the unicode version of PATH_INFO, for utf-8 version
|
||||
-- please use `utf_8_path_info', which is the real CGI value of PATH_INFO.
|
||||
|
||||
path_translated: detachable READABLE_STRING_32
|
||||
path_translated: detachable READABLE_STRING_8
|
||||
-- PATH_TRANSLATED is derived by taking any path-info component
|
||||
-- of the wgi_request URI (see section 6.1.6), decoding it (see
|
||||
-- section 3.1), parsing it as a URI in its own right, and
|
||||
@@ -907,6 +951,11 @@ feature -- Access: CGI meta parameters - 1.1
|
||||
--
|
||||
-- Servers SHOULD provide this metavariable to scripts if and
|
||||
-- only if the wgi_request URI includes a path-info component.
|
||||
--
|
||||
-- note: it is UTF_8 encoded.
|
||||
do
|
||||
Result := wgi_request.path_translated
|
||||
end
|
||||
|
||||
query_string: READABLE_STRING_8
|
||||
-- A URL-encoded string; the <query> part of the Script-URI. (See
|
||||
@@ -1853,7 +1902,7 @@ feature -- URL Utility
|
||||
elseif spos > 0 then
|
||||
i := spos
|
||||
end
|
||||
spos := l_rq_uri.substring_index (percent_encoded_path_info, i)
|
||||
spos := l_rq_uri.substring_index (path_info, i)
|
||||
if spos > 0 then
|
||||
l_base_url := l_rq_uri.substring (1, spos - 1)
|
||||
else
|
||||
@@ -1879,6 +1928,9 @@ feature {NONE} -- Implementation: URL Utility
|
||||
internal_url_base: detachable STRING
|
||||
-- URL base of potential script
|
||||
|
||||
internal_percent_encoded_path_info: detachable like percent_encoded_path_info
|
||||
-- Cache value of `percent_encoded_path_info'
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_raw_input_data_recorded (b: BOOLEAN)
|
||||
|
||||
Reference in New Issue
Block a user