diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-09-10 15:55:27 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-09-10 15:55:27 +0100 |
| commit | 1494d3c3a6283a00701ac452b8a9a5f8f2f4e9dd (patch) | |
| tree | 4e4467490b883fe075094a25ba28f05e62d21393 /lib | |
| parent | 162324eb530d781aa59acce597997646ee59d1eb (diff) | |
Support disabling external file access
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/docx-reader.js | 4 | ||||
| -rw-r--r-- | lib/docx/files.js | 9 | ||||
| -rw-r--r-- | lib/index.d.ts | 1 | ||||
| -rw-r--r-- | lib/index.js | 2 | ||||
| -rw-r--r-- | lib/options-reader.js | 1 |
5 files changed, 15 insertions, 2 deletions
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index 342ec46..f343dae 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -18,10 +18,12 @@ var commentsReader = require("./comments-reader"); var Files = require("./files").Files; -function read(docxFile, input) { +function read(docxFile, input, options) { input = input || {}; + options = options || {}; var files = new Files({ + externalFileAccess: options.externalFileAccess, relativeToFile: input.path }); diff --git a/lib/docx/files.js b/lib/docx/files.js index 4b09b69..cb8655c 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -13,6 +13,15 @@ exports.uriToPath = uriToPath; function Files(options) { + options = options || {}; + if (!options.externalFileAccess) { + return { + read: function(uri) { + return promises.reject(new Error("could not read external image '" + uri + "', external file access is disabled")); + } + }; + } + var base = options.relativeToFile ? dirname(options.relativeToFile) : null; function read(uri, encoding) { diff --git a/lib/index.d.ts b/lib/index.d.ts index 465c8f9..1f9af9e 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -33,6 +33,7 @@ interface Options { convertImage?: ImageConverter; ignoreEmptyParagraphs?: boolean; idPrefix?: string; + externalFileAccess?: boolean; transformDocument?: (element: any) => any; } diff --git a/lib/index.js b/lib/index.js index 03302c2..48dfb91 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,7 +39,7 @@ function convert(input, options) { }); }) .then(function(docxFile) { - return docxReader.read(docxFile, input) + return docxReader.read(docxFile, input, options) .then(function(documentResult) { return documentResult.map(options.transformDocument); }) diff --git a/lib/options-reader.js b/lib/options-reader.js index e16e472..4768159 100644 --- a/lib/options-reader.js +++ b/lib/options-reader.js @@ -63,6 +63,7 @@ var defaultStyleMap = exports._defaultStyleMap = [ ]; var standardOptions = exports._standardOptions = { + externalFileAccess: true, transformDocument: identity, includeDefaultStyleMap: true, includeEmbeddedStyleMap: true |
