Modify Headers API to correctly validate value.

This commit modifies the headers API script to correctly validate value. As a result of this change, more wpt tests pass. The commit also changes the expected test results.
This commit is contained in:
Jeena Lee 2016-08-10 15:30:12 -07:00
parent fabe2b8f7e
commit 69f4cf6808
6 changed files with 14 additions and 42 deletions

View file

@ -80,8 +80,11 @@ impl HeadersMethods for Headers {
return Ok(());
}
// Step 7
let mut combined_value = self.header_list.borrow_mut().get_raw(&valid_name).unwrap()[0].clone();
combined_value.push(b","[0]);
let mut combined_value: Vec<u8> = vec![];
if let Some(v) = self.header_list.borrow().get_raw(&valid_name) {
combined_value = v[0].clone();
combined_value.push(b","[0]);
}
combined_value.extend(valid_value.iter().cloned());
self.header_list.borrow_mut().set_raw(valid_name, vec![combined_value]);
Ok(())
@ -165,8 +168,6 @@ impl Headers {
match filler {
// Step 1
Some(HeadersOrByteStringSequenceSequence::Headers(h)) => {
// header_list_copy has type hyper::header::Headers
let header_list_copy = h.header_list.clone();
for header in h.header_list.borrow().iter() {
try!(self.Append(
ByteString::new(Vec::from(header.name())),
@ -346,20 +347,24 @@ fn is_field_name(name: &ByteString) -> bool {
// field-content = field-vchar [ 1*( SP / HTAB / field-vchar )
// field-vchar ]
fn is_field_content(value: &ByteString) -> bool {
if value.len() == 0 {
let value_len = value.len();
if value_len == 0 {
return false;
}
if !is_field_vchar(value[0]) {
return false;
}
for &ch in &value[1..value.len() - 1] {
if !is_field_vchar(ch) || !is_space(ch) || !is_htab(ch) {
return false;
if value_len > 2 {
for &ch in &value[1..value_len - 1] {
if !is_field_vchar(ch) && !is_space(ch) && !is_htab(ch) {
return false;
}
}
}
if !is_field_vchar(value[value.len() - 1]) {
if !is_field_vchar(value[value_len - 1]) {
return false;
}

View file

@ -3,21 +3,12 @@
[Create headers from empty object]
expected: FAIL
[Create headers with sequence]
expected: FAIL
[Create headers with OpenEndedDictionary]
expected: FAIL
[Create headers with existing headers]
expected: FAIL
[Check append method]
expected: FAIL
[Check set method]
expected: FAIL
[Check has method]
expected: FAIL

View file

@ -3,12 +3,3 @@
[Create headers, names use characters with different case]
expected: FAIL
[Check append method, names use characters with different case]
expected: FAIL
[Check set method, names use characters with different case]
expected: FAIL
[Check delete method, names use characters with different case]
expected: FAIL

View file

@ -3,12 +3,6 @@
[Create headers using same name for different values]
expected: FAIL
[Check delete and has methods when using same name for different values]
expected: FAIL
[Check set methods when called with already used name]
expected: FAIL
[Check append methods when called with already used name]
expected: FAIL

View file

@ -1,8 +1,5 @@
[headers-errors.html]
type: testharness
[Headers forEach throws if argument is not callable]
expected: FAIL
[Headers forEach loop should stop if callback is throwing exception]
expected: FAIL

View file

@ -3,9 +3,3 @@
[Create headers with not normalized values]
expected: FAIL
[Check append method whith not normalized values]
expected: FAIL
[Check set method whith not normalized values]
expected: FAIL