aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2021-11-01 19:08:28 +0000
committerMichael Williamson <mike@zwobble.org>2021-11-01 19:08:28 +0000
commite7803837d2a0214bc144f640bf3e2482c19ac35f (patch)
tree034021c807fdbfb87b7445ebe787bc01a510ec17
parent47f27abda77e15faec56cd8e215d3156a36aca1d (diff)
Handle a:blip elements without image file
-rw-r--r--NEWS5
-rw-r--r--lib/docx/body-reader.js11
-rw-r--r--test/docx/body-reader.tests.js12
3 files changed, 26 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index b48ffea..b4eb2ad 100644
--- a/NEWS
+++ b/NEWS
@@ -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"),