From cd83a60689fdecb5995b36bbce9fa090dfca9d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20Jagodzi=C5=84ski?= Date: Thu, 22 Aug 2024 16:48:36 +0200 Subject: [PATCH] Skip img tag with blank url --- src/extractItemsFromElement.js | 4 +++- test/convertDescriptionToItems.spec.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/extractItemsFromElement.js b/src/extractItemsFromElement.js index 6ab7a21..fa7fe2b 100644 --- a/src/extractItemsFromElement.js +++ b/src/extractItemsFromElement.js @@ -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; diff --git a/test/convertDescriptionToItems.spec.js b/test/convertDescriptionToItems.spec.js index c76abe9..0eeeb40 100644 --- a/test/convertDescriptionToItems.spec.js +++ b/test/convertDescriptionToItems.spec.js @@ -172,6 +172,21 @@ describe("convertDescriptionToItems", () => { items.should.eql(expectedItems); }); + given("", " ").it("should skip img tag with blank url", (url) => { + // given + const html = givenHtmlWithContent(` + +
This is a test text
+ `); + + // when + const items = convertDescriptionToItems(html, options); + + // then + const expectedItems = [new TextItem("

This is a test text

")]; + items.should.eql(expectedItems); + }); + it("should skip tag containing html that converts to empty standardized html", () => { // given const html = givenHtmlWithContent(`