Skip to content

Commit

Permalink
don't crash on <img src="#x"> (mdn#3187)
Browse files Browse the repository at this point in the history
Fixes mdn#3186
  • Loading branch information
peterbe committed Jun 1, 2021
1 parent 018e04f commit 5135c58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/check-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function checkImageReferences(doc, $, options, { url, rawContent }) {
// a new function dedicated to that.
let finalSrc = null;

if (!src.trim()) {
if (!src.split("#")[0].trim()) {
if (checkImages) {
addImageFlaw(img, src, {
explanation: "Empty img 'src' attribute",
Expand Down
7 changes: 7 additions & 0 deletions testing/content/files/en-us/web/empty_image/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
<img src="">
Pretty nihilistic, eh?
</p>

<p>
This one is based on make sure we've solved:
<a href="https://github.com/mdn/yari/issues/3186">issue#3186</a>
</p>

<img src="#anchor">
7 changes: 6 additions & 1 deletion testing/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,12 +970,17 @@ test("img tags with an empty 'src' should be a flaw", () => {
expect(fs.existsSync(builtFolder)).toBeTruthy();
const jsonFile = path.join(builtFolder, "index.json");
const { doc } = JSON.parse(fs.readFileSync(jsonFile));
expect(doc.flaws.images.length).toBe(1);
expect(doc.flaws.images.length).toBe(2);
expect(doc.flaws.images[0].explanation).toBe("Empty img 'src' attribute");
expect(doc.flaws.images[0].fixable).toBeFalsy();
expect(doc.flaws.images[0].externalImage).toBeFalsy();
expect(doc.flaws.images[0].line).toBe(8);
expect(doc.flaws.images[0].column).toBe(13);
expect(doc.flaws.images[1].explanation).toBe("Empty img 'src' attribute");
expect(doc.flaws.images[1].fixable).toBeFalsy();
expect(doc.flaws.images[1].externalImage).toBeFalsy();
expect(doc.flaws.images[1].line).toBe(17);
expect(doc.flaws.images[1].column).toBe(11);
});

test("img with the image_widths flaw", () => {
Expand Down

0 comments on commit 5135c58

Please sign in to comment.