Auto merge of #12003 - Manishearth:no-crash-url-parse, r=jdm

Don't crash when <img> fails to parse its src

Fixes #11992

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12003)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-07-05 14:12:21 -07:00 committed by GitHub
commit 5574a4e4c8
6 changed files with 111 additions and 35 deletions

View file

@ -36276,6 +36276,12 @@
"path": "html/semantics/document-metadata/the-link-element/document-without-browsing-context.html",
"url": "/html/semantics/document-metadata/the-link-element/document-without-browsing-context.html"
}
],
"html/semantics/embedded-content/the-img-element/invalid-src.html": [
{
"path": "html/semantics/embedded-content/the-img-element/invalid-src.html",
"url": "/html/semantics/embedded-content/the-img-element/invalid-src.html"
}
]
}
},

View file

@ -1,3 +1,11 @@
[fail-to-resolve.html]
type: testharness
expected: CRASH
[<img srcset="//[">]
expected: FAIL
[<img srcset="//[" src="/images/red.png">]
expected: FAIL
[<img srcset="//[, /images/red.png">]
expected: FAIL

View file

@ -1,8 +1,5 @@
[update-the-source-set.html]
type: testharness
[<img src="" data-expect="">]
expected: FAIL
[<img srcset="data:,b" src="data:,a" data-expect="data:,b">]
expected: FAIL

View file

@ -0,0 +1,21 @@
<!doctype html>
<meta charset="utf-8">
<title>Loading a non-parsing URL as an image should silently fail; triggering appropriate events</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<img id=myimg />
<script>
async_test(function(t) {
var img = document.getElementById("myimg");
img.src = "http://also a broken url";
var errorevent = false;
// The errors should be queued in the event loop, so they should only trigger
// after this block of code finishes, not during the img.src setter itself
img.addEventListener('error', t.step_func(function(){errorevent = true;}));
img.addEventListener('loadend', t.step_func_done(function() {
assert_true(errorevent, "error event fired");
}));
});
</script>