Commit b3f24f51 authored by Shanmuga Pandi M's avatar Shanmuga Pandi M Committed by Commit Bot

CSSURLImageValue should validate URLs

As per the spec[1],
Constructing CSSURLImageValue should throw an error,
if the URL is invalid.
[1] https://drafts.css-houdini.org/css-typed-om-1/#dom-cssurlimagevalue-cssurlimagevalue

Bug: 791434
Change-Id: I06ae5dad378ca91ce827f64ff56498a06c9963af
Reviewed-on: https://chromium-review.googlesource.com/805635Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Shanmuga Pandi <shanmuga.m@samsung.com>
Cr-Commit-Position: refs/heads/master@{#521574}
parent bd6f0233
This is a testharness.js-based test.
FAIL Constructing a CSSURLImageValue with an invalid URL throws a TypeError assert_throws: function "() => new CSSURLImageValue('not url')" did not throw
PASS Constructing a CSSURLImageValue with an invalid URL throws a TypeError
PASS Constructing a CSSURLImageValue with a valid URL puts it in an unloaded state
PASS CSSURLImageValue.url is readonly
PASS Loading a CSSURLImageValue from a URL sets its state to loaded
......
......@@ -26,7 +26,7 @@ const gBase64TestUrl = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=';
const gBadTestUrl = document.location.href;
test(() => {
assert_throws(new TypeError(), () => new CSSURLImageValue('not url'));
assert_throws(new TypeError(), () => new CSSURLImageValue("file://:This is invalid url"));
}, 'Constructing a CSSURLImageValue with an invalid URL throws a TypeError');
test(() => {
......
......@@ -16,13 +16,19 @@ class CORE_EXPORT CSSURLImageValue final : public CSSStyleImageValue {
public:
static CSSURLImageValue* Create(ScriptState* script_state,
const AtomicString& url) {
const AtomicString& url,
ExceptionState& exception_state) {
const auto* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context);
KURL parsed_url = execution_context->CompleteURL(url);
if (!parsed_url.IsValid()) {
exception_state.ThrowTypeError("Failed to parse URL from " + url);
return nullptr;
}
// Use absolute URL for CSSImageValue but keep relative URL for
// getter and serialization.
return new CSSURLImageValue(CSSImageValue::Create(
url, execution_context->CompleteURL(url), Referrer()));
return new CSSURLImageValue(
CSSImageValue::Create(url, parsed_url, Referrer()));
}
static CSSURLImageValue* Create(const CSSImageValue* image_value) {
return new CSSURLImageValue(image_value);
......
......@@ -8,6 +8,7 @@
Constructor(USVString url),
ConstructorCallWith=ScriptState,
Exposed=(Window,PaintWorklet),
RaisesException=Constructor,
RuntimeEnabled=CSSTypedOM
] interface CSSURLImageValue : CSSImageValue {
readonly attribute USVString url;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment