aboutsummaryrefslogtreecommitdiff
path: root/lib/docx-reader.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-10 21:07:01 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-10 21:07:01 +0100
commit9a4c6832d7f3cd64744ec525ab763617aa675bad (patch)
tree9a4fa47bbccd6f753f94b7a9ff4ad15bd58ea806 /lib/docx-reader.js
parente67ed8a6715942beed2c90423d81119c200aa2ec (diff)
Explicitly map XML namespaces for safety
Diffstat (limited to 'lib/docx-reader.js')
-rw-r--r--lib/docx-reader.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/docx-reader.js b/lib/docx-reader.js
index 35f1627..1012068 100644
--- a/lib/docx-reader.js
+++ b/lib/docx-reader.js
@@ -87,9 +87,19 @@ function openZip(zipPath) {
}
function readXmlFile(docxFile, path) {
+ var xmlNamespaceMap = {
+ "http://schemas.openxmlformats.org/wordprocessingml/2006/main": "w",
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships": "r",
+ "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing": "wp",
+ "http://schemas.openxmlformats.org/drawingml/2006/main": "a",
+ "http://schemas.openxmlformats.org/drawingml/2006/picture": "pic"
+ };
+
if (docxFile.exists(path)) {
return docxFile.read(path, "utf-8")
- .then(xmlreader.read);
+ .then(function(xmlString) {
+ return xmlreader.read(xmlString, xmlNamespaceMap);
+ });
} else {
return null;
}
@@ -98,7 +108,7 @@ function readXmlFile(docxFile, path) {
function readRelationships(relationshipsXml) {
var relationships = {};
relationshipsXml.root.children.forEach(function(child) {
- if (child.name === "Relationship") {
+ if (child.name === "{http://schemas.openxmlformats.org/package/2006/relationships}:Relationship") {
relationships[child.attributes.Id] = {
target: child.attributes.Target
};