mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Correctly initialize URL.searchParams
This commit is contained in:
parent
7932ab6ac2
commit
85de5ec743
3 changed files with 25 additions and 28 deletions
|
@ -42,6 +42,10 @@ impl URL {
|
||||||
global, URLBinding::Wrap)
|
global, URLBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn query_pairs(&self) -> Vec<(String, String)> {
|
||||||
|
self.url.borrow().query_pairs().into_owned().collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_query_pairs(&self, pairs: &[(String, String)]) {
|
pub fn set_query_pairs(&self, pairs: &[(String, String)]) {
|
||||||
let mut url = self.url.borrow_mut();
|
let mut url = self.url.borrow_mut();
|
||||||
url.query_pairs_mut().clear().extend_pairs(pairs);
|
url.query_pairs_mut().clear().extend_pairs(pairs);
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl URLSearchParams {
|
||||||
fn new_inherited(url: Option<&URL>) -> URLSearchParams {
|
fn new_inherited(url: Option<&URL>) -> URLSearchParams {
|
||||||
URLSearchParams {
|
URLSearchParams {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
list: DOMRefCell::new(vec![]),
|
list: DOMRefCell::new(url.map_or(Vec::new(), |url| url.query_pairs())),
|
||||||
url: MutableWeakRef::new(url),
|
url: MutableWeakRef::new(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,26 +111,28 @@ impl URLSearchParamsMethods for URLSearchParams {
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-set
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-set
|
||||||
fn Set(&self, name: USVString, value: USVString) {
|
fn Set(&self, name: USVString, value: USVString) {
|
||||||
// Step 1.
|
{
|
||||||
let mut list = self.list.borrow_mut();
|
// Step 1.
|
||||||
let mut index = None;
|
let mut list = self.list.borrow_mut();
|
||||||
let mut i = 0;
|
let mut index = None;
|
||||||
list.retain(|&(ref k, _)| {
|
let mut i = 0;
|
||||||
if index.is_none() {
|
list.retain(|&(ref k, _)| {
|
||||||
if k == &name.0 {
|
if index.is_none() {
|
||||||
index = Some(i);
|
if k == &name.0 {
|
||||||
|
index = Some(i);
|
||||||
|
} else {
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
true
|
||||||
} else {
|
} else {
|
||||||
i += 1;
|
k != &name.0
|
||||||
}
|
}
|
||||||
true
|
});
|
||||||
} else {
|
match index {
|
||||||
k != &name.0
|
Some(index) => list[index].1 = value.0,
|
||||||
}
|
None => list.push((name.0, value.0)), // Step 2.
|
||||||
});
|
};
|
||||||
match index {
|
} // Un-borrow self.list
|
||||||
Some(index) => list[index].1 = value.0,
|
|
||||||
None => list.push((name.0, value.0)), // Step 2.
|
|
||||||
};
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
self.update_steps();
|
self.update_steps();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,15 +75,6 @@
|
||||||
[Parsing: <h\tt\nt\rp://h\to\ns\rt:9\t0\n0\r0/p\ta\nt\rh?q\tu\ne\rry#f\tr\na\rg> against <about:blank>]
|
[Parsing: <h\tt\nt\rp://h\to\ns\rt:9\t0\n0\r0/p\ta\nt\rh?q\tu\ne\rry#f\tr\na\rg> against <about:blank>]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[URL.searchParams updating, clearing]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.searchParams and URL.search setters, update propagation]
|
[URL.searchParams and URL.search setters, update propagation]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Parsing: <?a=b&c=d> against <http://example.org/foo/bar>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Parsing: <??a=b&c=d> against <http://example.org/foo/bar>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue