mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Auto merge of #29574 - ohno418:implement-URL-static-canParse, r=jdm
Implement URL.canParse Add an implementation of `URL.canParse` as a static method. See [here][1] for the specification. [1]: https://url.spec.whatwg.org/#dom-url-canparse Signed-off-by: Yutaro Ohno <yutaro.ono.418@gmail.com> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #29533(GitHub issue number if applicable) <!-- Either: --> - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
d42f5449bd
3 changed files with 24 additions and 44 deletions
|
@ -111,6 +111,27 @@ impl URL {
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://url.spec.whatwg.org/#dom-url-canparse
|
||||||
|
pub fn CanParse(_global: &GlobalScope, url: USVString, base: Option<USVString>) -> bool {
|
||||||
|
// Step 1.
|
||||||
|
let parsed_base = match base {
|
||||||
|
None => None,
|
||||||
|
Some(base) => match ServoUrl::parse(&base.0) {
|
||||||
|
Ok(base) => Some(base),
|
||||||
|
Err(_) => {
|
||||||
|
// Step 2.1
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
match ServoUrl::parse_with_base(parsed_base.as_ref(), &url.0) {
|
||||||
|
// Step 3
|
||||||
|
Ok(_) => true,
|
||||||
|
// Step 2.2
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-createObjectURL
|
// https://w3c.github.io/FileAPI/#dfn-createObjectURL
|
||||||
pub fn CreateObjectURL(global: &GlobalScope, blob: &Blob) -> DOMString {
|
pub fn CreateObjectURL(global: &GlobalScope, blob: &Blob) -> DOMString {
|
||||||
// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround
|
// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
LegacyWindowAlias=webkitURL]
|
LegacyWindowAlias=webkitURL]
|
||||||
interface URL {
|
interface URL {
|
||||||
[Throws] constructor(USVString url, optional USVString base);
|
[Throws] constructor(USVString url, optional USVString base);
|
||||||
|
|
||||||
|
static boolean canParse(USVString url, optional USVString base);
|
||||||
|
|
||||||
[SetterThrows]
|
[SetterThrows]
|
||||||
stringifier attribute USVString href;
|
stringifier attribute USVString href;
|
||||||
readonly attribute USVString origin;
|
readonly attribute USVString origin;
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
[url-statics-canparse.any.html]
|
|
||||||
[URL.canParse(undefined, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(a:b, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(undefined, a:b)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(a:/b, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(undefined, a:/b)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(https://test:test, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(a, https://b/)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[url-statics-canparse.any.worker.html]
|
|
||||||
[URL.canParse(undefined, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(a:b, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(undefined, a:b)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(a:/b, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(undefined, a:/b)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(https://test:test, undefined)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL.canParse(a, https://b/)]
|
|
||||||
expected: FAIL
|
|
Loading…
Add table
Add a link
Reference in a new issue