Fixed type having a semicolon in a parameter value such as

"text/plain; param1=%"something;foo=bar%"; param2=%"another-thing%"
This commit is contained in:
2013-09-16 18:04:43 +02:00
parent f8a0bbf88b
commit 2f3a462c42
3 changed files with 73 additions and 30 deletions

View File

@@ -63,6 +63,7 @@ feature {NONE} -- Initialization
t: STRING_8
i,n: INTEGER
p: INTEGER
cl: CELL [INTEGER]
do
-- Ignore starting space (should not be any)
from
@@ -79,18 +80,13 @@ feature {NONE} -- Initialization
if p > 0 then
t := s.substring (i, p - 1)
from
create cl.put (p)
i := p + 1
until
i >= n
loop
i := p + 1
p := s.index_of (';', i)
if p = 0 then
add_parameter_from_string (s, i, n)
i := n
else
add_parameter_from_string (s, i, p - 1)
i := p + 1
end
add_parameter_from_string (s, i, cl)
i := cl.item
end
else
t := s.substring (i, n)
@@ -271,45 +267,80 @@ feature -- Element change
feature {NONE} -- Implementation
add_parameter_from_string (s: READABLE_STRING_8; start_index, end_index: INTEGER)
add_parameter_from_string (s: READABLE_STRING_8; start_index: INTEGER; out_end_index: CELL [INTEGER])
-- Add parameter from string " attribute=value "
-- and put in `out_end_index' the index after found parameter.
local
n: INTEGER
pn,pv: STRING_8
i: INTEGER
p: INTEGER
p, q: INTEGER
err: BOOLEAN
do
-- Skip spaces
n := s.count
-- Skip spaces
from
i := start_index
until
i > end_index or not s[i].is_space
i > n or not s[i].is_space
loop
i := i + 1
end
if i < end_index then
if s[i] = ';' then
-- empty parameter
out_end_index.replace (i + 1)
elseif i < n then
p := s.index_of ('=', i)
if p > 0 and p < end_index then
if p > 0 then
pn := s.substring (i, p - 1)
pv := s.substring (p + 1, end_index)
pv.right_adjust
if pv.count > 0 and pv [1] = '%"' then
if pv [pv.count] = '%"' then
pv := pv.substring (2, pv.count - 1)
if p >= n then
pv := ""
out_end_index.replace (n + 1)
else
if s[p+1] = '%"' then
q := s.index_of ('%"', p + 2)
if q > 0 then
pv := s.substring (p + 2, q - 1)
from
i := q + 1
until
i > n or not s[i].is_space
loop
i := i + 1
end
if s[i] = ';' then
i := i + 1
end
out_end_index.replace (i)
else
err := True
pv := ""
-- missing closing double quote.
end
else
err := True
-- missing closing double quote.
q := s.index_of (';', p + 1)
if q = 0 then
q := n + 1
end
pv := s.substring (p + 1, q - 1)
out_end_index.replace (q + 1)
end
pv.right_adjust
if not err then
add_parameter (pn, pv)
end
end
if not err then
add_parameter (pn, pv)
end
else
-- expecting: attribute "=" value
err := True
end
end
if err then
out_end_index.replace (n + 1)
end
has_error := has_error or err
ensure
entry_processed: out_end_index.item > start_index
end
feature {NONE} -- Internal

View File

@@ -12,9 +12,16 @@ inherit
feature -- Content type
test_http_content_type
test_http_content_types_with_params
local
ct: HTTP_CONTENT_TYPE
do
test_content_type_with_params ("text/plain; param1=%"something;foo=bar%"; param2=%"another-thing%"",
"text", "plain", <<["param1", "something;foo=bar"], ["param2", "another-thing"]>>
)
end
test_http_content_type
do
test_content_type ("application/atom+xml", "application", "atom+xml") -- Atom feeds
test_content_type ("application/ecmascript", "application", "ecmascript") -- ECMAScript/JavaScript; Defined in RFC 4329 (equivalent to application/javascript but with stricter processing rules)

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="tests" uuid="0582ACC2-11D8-4FE5-888D-61837BA8F43E">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-11-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-11-0 http://www.eiffel.com/developers/xml/configuration-1-11-0.xsd" name="tests" uuid="0582ACC2-11D8-4FE5-888D-61837BA8F43E">
<target name="tests">
<root class="AUTOTEST" feature="make"/>
<file_rule>
@@ -7,11 +7,16 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="transitional" syntax="standard">
<assertions precondition="true" postcondition="true" check="true"/>
</option>
<setting name="concurrency" value="none"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="http" location="..\http-safe.ecf" readonly="false"/>
<library name="http" location="..\http-safe.ecf" readonly="false">
<option>
<assertions precondition="true" postcondition="true" check="true"/>
</option>
</library>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="src" location=".\" recursive="true"/>
</target>