diff options
| -rw-r--r-- | NEWS | 5 | ||||
| -rw-r--r-- | lib/docx/body-reader.js | 11 | ||||
| -rw-r--r-- | test/docx/body-reader.tests.js | 12 |
3 files changed, 26 insertions, 2 deletions
@@ -1,3 +1,8 @@ +# 1.4.20 + +* Emit warning instead of throwing exception when image file cannot be found for + a:blip elements. + # 1.4.19 * Add TypeScript declarations. diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 0d04ccd..4bd38a9 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -462,7 +462,12 @@ function BodyReader(options) { function readBlip(element, blip) { var properties = element.first("wp:docPr").attributes; var altText = isBlank(properties.descr) ? properties.title : properties.descr; - return readImage(findBlipImageFile(blip), altText); + var blipImageFile = findBlipImageFile(blip); + if (blipImageFile === null) { + return emptyResultWithMessages([warning("Could not find image file for a:blip element")]); + } else { + return readImage(blipImageFile, altText); + } } function isBlank(value) { @@ -474,12 +479,14 @@ function BodyReader(options) { var linkRelationshipId = blip.attributes["r:link"]; if (embedRelationshipId) { return findEmbeddedImageFile(embedRelationshipId); - } else { + } else if (linkRelationshipId) { var imagePath = relationships.findTargetByRelationshipId(linkRelationshipId); return { path: imagePath, read: files.read.bind(files, imagePath) }; + } else { + return null; } } diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index c539aad..2e53200 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -1087,6 +1087,18 @@ test("can read linked pictures", function() { })); }); +test("warning if blip has no image file", function() { + var drawing = createInlineImage({ + blip: new XmlElement("a:blip"), + description: "It's a hat" + }); + + var result = readXmlElement(drawing); + + assert.deepEqual(result.messages, [warning("Could not find image file for a:blip element")]); + assert.deepEqual(result.value, []); +}); + test("warning if unsupported image type", function() { var drawing = createInlineImage({ blip: createEmbeddedBlip("rId5"), |
