Auto merge of #16063 - methyl:image-usemap-panics, r=nox

Avoid panics for empty or multibyte image usemap

<!-- Please describe your changes on the following line: -->
Some check were added to make sure we can call `split_at` with no risk of panics (when value is empty or the first char is multibyte).

---
<!-- 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 #15883 (github issue number if applicable).
- [x] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16063)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-12 07:34:27 -05:00 committed by GitHub
commit 69eda6a60c
3 changed files with 33 additions and 0 deletions

View file

@ -423,6 +423,11 @@ impl HTMLImageElement {
};
let value = usemap_attr.value();
if value.len() == 0 || !value.is_char_boundary(1) {
return None
}
let (first, last) = value.split_at(1);
if first != "#" || last.len() == 0 {