mirror of
https://github.com/servo/servo.git
synced 2025-07-22 06:43:40 +01:00
Remove treatment of whitespace in the construction of a for data entry list, move it to the encoding stage (#32868)
Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
parent
9f151faf1d
commit
bc75bf4cfa
3 changed files with 43 additions and 86 deletions
|
@ -1174,37 +1174,6 @@ impl HTMLFormElement {
|
||||||
submitter: Option<FormSubmitterElement>,
|
submitter: Option<FormSubmitterElement>,
|
||||||
encoding: Option<&'static Encoding>,
|
encoding: Option<&'static Encoding>,
|
||||||
) -> Option<Vec<FormDatum>> {
|
) -> Option<Vec<FormDatum>> {
|
||||||
fn clean_crlf(s: &str) -> DOMString {
|
|
||||||
// Step 4
|
|
||||||
let mut buf = "".to_owned();
|
|
||||||
let mut prev = ' ';
|
|
||||||
for ch in s.chars() {
|
|
||||||
match ch {
|
|
||||||
'\n' if prev != '\r' => {
|
|
||||||
buf.push('\r');
|
|
||||||
buf.push('\n');
|
|
||||||
},
|
|
||||||
'\n' => {
|
|
||||||
buf.push('\n');
|
|
||||||
},
|
|
||||||
// This character isn't LF but is
|
|
||||||
// preceded by CR
|
|
||||||
_ if prev == '\r' => {
|
|
||||||
buf.push('\r');
|
|
||||||
buf.push('\n');
|
|
||||||
buf.push(ch);
|
|
||||||
},
|
|
||||||
_ => buf.push(ch),
|
|
||||||
};
|
|
||||||
prev = ch;
|
|
||||||
}
|
|
||||||
// In case the last character was CR
|
|
||||||
if prev == '\r' {
|
|
||||||
buf.push('\n');
|
|
||||||
}
|
|
||||||
DOMString::from(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 1
|
// Step 1
|
||||||
if self.constructing_entry_list.get() {
|
if self.constructing_entry_list.get() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -1214,19 +1183,7 @@ impl HTMLFormElement {
|
||||||
self.constructing_entry_list.set(true);
|
self.constructing_entry_list.set(true);
|
||||||
|
|
||||||
// Step 3-6
|
// Step 3-6
|
||||||
let mut ret = self.get_unclean_dataset(submitter, encoding);
|
let ret = self.get_unclean_dataset(submitter, encoding);
|
||||||
for datum in &mut ret {
|
|
||||||
match &*datum.ty {
|
|
||||||
"file" | "textarea" => (), // TODO
|
|
||||||
_ => {
|
|
||||||
datum.name = clean_crlf(&datum.name);
|
|
||||||
datum.value = FormDatumValue::String(clean_crlf(match datum.value {
|
|
||||||
FormDatumValue::String(ref s) => s,
|
|
||||||
FormDatumValue::File(_) => unreachable!(),
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
|
|
||||||
|
@ -1782,20 +1739,56 @@ impl FormControlElementHelpers for Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm
|
/// <https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm>
|
||||||
pub fn encode_multipart_form_data(
|
pub fn encode_multipart_form_data(
|
||||||
form_data: &mut [FormDatum],
|
form_data: &mut [FormDatum],
|
||||||
boundary: String,
|
boundary: String,
|
||||||
encoding: &'static Encoding,
|
encoding: &'static Encoding,
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
// Step 1
|
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
|
|
||||||
// Step 2
|
// Newline replacement routine as described in Step 1
|
||||||
for entry in form_data.iter_mut() {
|
fn clean_crlf(s: &str) -> DOMString {
|
||||||
// TODO: Step 2.1
|
let mut buf = "".to_owned();
|
||||||
|
let mut prev = ' ';
|
||||||
|
for ch in s.chars() {
|
||||||
|
match ch {
|
||||||
|
'\n' if prev != '\r' => {
|
||||||
|
buf.push('\r');
|
||||||
|
buf.push('\n');
|
||||||
|
},
|
||||||
|
'\n' => {
|
||||||
|
buf.push('\n');
|
||||||
|
},
|
||||||
|
// This character isn't LF but is
|
||||||
|
// preceded by CR
|
||||||
|
_ if prev == '\r' => {
|
||||||
|
buf.push('\r');
|
||||||
|
buf.push('\n');
|
||||||
|
buf.push(ch);
|
||||||
|
},
|
||||||
|
_ => buf.push(ch),
|
||||||
|
};
|
||||||
|
prev = ch;
|
||||||
|
}
|
||||||
|
// In case the last character was CR
|
||||||
|
if prev == '\r' {
|
||||||
|
buf.push('\n');
|
||||||
|
}
|
||||||
|
DOMString::from(buf)
|
||||||
|
}
|
||||||
|
|
||||||
// Step 3
|
for entry in form_data.iter_mut() {
|
||||||
|
// Step 1.1: Perform newline replacement on entry's name
|
||||||
|
entry.name = clean_crlf(&entry.name);
|
||||||
|
|
||||||
|
// Step 1.2: If entry's value is not a File object, perform newline replacement on entry's
|
||||||
|
// value
|
||||||
|
if let FormDatumValue::String(ref s) = entry.value {
|
||||||
|
entry.value = FormDatumValue::String(clean_crlf(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Return the byte sequence resulting from encoding the entry list.
|
||||||
// https://tools.ietf.org/html/rfc7578#section-4
|
// https://tools.ietf.org/html/rfc7578#section-4
|
||||||
// NOTE(izgzhen): The encoding here expected by most servers seems different from
|
// NOTE(izgzhen): The encoding here expected by most servers seems different from
|
||||||
// what spec says (that it should start with a '\r\n').
|
// what spec says (that it should start with a '\r\n').
|
||||||
|
|
|
@ -23,24 +23,6 @@
|
||||||
[Form newline normalization: \\n\\r in the filename stays unchanged]
|
[Form newline normalization: \\n\\r in the filename stays unchanged]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n in the value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\r in the value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n\\r in the value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n in the name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\r in the name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n\\r in the name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n in the filename]
|
[Constructing the entry list shouldn't perform newline normalization: \\n in the filename]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -23,24 +23,6 @@
|
||||||
[Form newline normalization: \\n\\r in the filename stays unchanged]
|
[Form newline normalization: \\n\\r in the filename stays unchanged]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n in the value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\r in the value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n\\r in the value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n in the name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\r in the name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n\\r in the name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Constructing the entry list shouldn't perform newline normalization: \\n in the filename]
|
[Constructing the entry list shouldn't perform newline normalization: \\n in the filename]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue