Skip to content

Commit

Permalink
Modify Headers API to correctly validate value.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeenalee committed Aug 12, 2016
1 parent fabe2b8 commit 69f4cf6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 42 deletions.
23 changes: 14 additions & 9 deletions components/script/dom/headers.rs
Expand Up @@ -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(())
Expand Down Expand Up @@ -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())),
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 0 additions & 9 deletions tests/wpt/metadata/fetch/api/headers/headers-basic.html.ini
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions tests/wpt/metadata/fetch/api/headers/headers-casing.html.ini
Expand Up @@ -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

6 changes: 0 additions & 6 deletions tests/wpt/metadata/fetch/api/headers/headers-combine.html.ini
Expand Up @@ -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

3 changes: 0 additions & 3 deletions tests/wpt/metadata/fetch/api/headers/headers-errors.html.ini
@@ -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

Expand Up @@ -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

0 comments on commit 69f4cf6

Please sign in to comment.