summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Price <studiochris@users.noreply.github.com>2014-08-18 22:26:49 -0400
committerMichael Williamson <mike@zwobble.org>2014-08-20 10:38:50 +0100
commit76adc351b75b2489f3ef009a7e39df3dabadb50d (patch)
treeb12e26a3e3aa3f19ce30f25bda731c414e01d9c2
parent1ff800d5148068531419b179c8b9257ba9bd2e55 (diff)
Remove potential Unicode BOM after reading XML file
-rw-r--r--lib/docx/office-xml-reader.js3
-rw-r--r--tests/mammoth.tests.js8
-rw-r--r--tests/test-data/bom.docxbin0 -> 2836 bytes
3 files changed, 11 insertions, 0 deletions
diff --git a/lib/docx/office-xml-reader.js b/lib/docx/office-xml-reader.js
index 39b700e..861b11e 100644
--- a/lib/docx/office-xml-reader.js
+++ b/lib/docx/office-xml-reader.js
@@ -22,6 +22,9 @@ function read(xmlString) {
function readXmlFromZipFile(docxFile, path) {
if (docxFile.exists(path)) {
return docxFile.read(path, "utf-8")
+ .then(function (xmlString) {
+ return xmlString.replace(/^\uFEFF/g, '');
+ })
.then(read);
} else {
return promises.resolve(null);
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index e0c1f6c..9be7006 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -32,6 +32,14 @@ describe('mammoth', function() {
});
});
+ test('should read docx xml files with unicode byte order mark', function() {
+ var docxPath = path.join(__dirname, "test-data/bom.docx");
+ return mammoth.convertToHtml({path: docxPath}).then(function (result) {
+ assert.equal(result.value, "<p>This XML has a byte order mark.</p>");
+ assert.deepEqual(result.messages, []);
+ });
+ });
+
test('style map can be expressed as string', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
diff --git a/tests/test-data/bom.docx b/tests/test-data/bom.docx
new file mode 100644
index 0000000..3881238
--- /dev/null
+++ b/tests/test-data/bom.docx
Binary files differ