diff options
| author | Liam Z <sethverlo5@gmail.com> | 2016-10-02 19:49:56 +0800 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-10-02 12:49:56 +0100 |
| commit | 514226e8c04ca483adff18bbad3a66f9b1593f07 (patch) | |
| tree | 0f468277a7135dca45227e0576c4508a4cf07fe4 | |
| parent | 3eb1a5207b39b6150d828867cc684e5da94482f6 (diff) | |
Ignore v:imagedata elements without relationship ID with warning
| -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), |
