diff options
| -rw-r--r-- | lib/docx/body-reader.js | 12 | ||||
| -rw-r--r-- | test/docx/body-reader.tests.js | 9 |
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 732a8d2..4a1655e 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -340,9 +340,15 @@ function BodyReader(options) { } function readImageData(element) { - return readImage( - findEmbeddedImageFile(element.attributes["r:id"]), - element.attributes["o:title"]); + var relationshipId = element.attributes['r:id']; + + if (relationshipId) { + return readImage( + findEmbeddedImageFile(relationshipId), + element.attributes["o:title"]); + } else { + return emptyResultWithMessages([warning("A v:imagedata element without a relationship ID was ignored")]); + } } function findEmbeddedImageFile(relationshipId) { diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index 878d279..62178ec 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -454,6 +454,15 @@ test("can read imagedata elements with r:id attribute", function() { }))); }); +test("when v:imagedata element has no relationship ID then it is ignored with warning", function() { + var imagedataElement = new XmlElement("v:imagedata"); + + var result = readXmlElement(imagedataElement); + + assert.deepEqual(result.value, []); + assert.deepEqual(result.messages, [warning("A v:imagedata element without a relationship ID was ignored")]); +}); + test("can read inline pictures", function() { var drawing = createInlineImage({ blip: createEmbeddedBlip(IMAGE_RELATIONSHIP_ID), |
