Skip to content

Commit

Permalink
Skip img tag with blank url
Browse files Browse the repository at this point in the history
  • Loading branch information
hjagodzinski committed Aug 26, 2024
1 parent 0600d7c commit cd83a60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/extractItemsFromElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function extractItemsFromElement(childNode) {
}
// if element is img -> create img section
if (childNode.tagName === IMG_TAG_NAME) {
items.push(new ImageItem(childNode.src));
if (!isBlankText(childNode.src)) {
items.push(new ImageItem(childNode.src));
}
}

return items;
Expand Down
15 changes: 15 additions & 0 deletions test/convertDescriptionToItems.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ describe("convertDescriptionToItems", () => {
items.should.eql(expectedItems);
});

given("", " ").it("should skip img tag with blank url", (url) => {
// given
const html = givenHtmlWithContent(`
<img src="${url}" />
<div>This is a test text</div>
`);

// when
const items = convertDescriptionToItems(html, options);

// then
const expectedItems = [new TextItem("<p>This is a test text</p>")];
items.should.eql(expectedItems);
});

it("should skip tag containing html that converts to empty standardized html", () => {
// given
const html = givenHtmlWithContent(`
Expand Down

0 comments on commit cd83a60

Please sign in to comment.