Commit 2888fa1 for mammothjs
commit 2888fa158d67c1419199f152326e12a05618b53e
Author: Michael Williamson <mike@zwobble.org>
Date: Fri Aug 28 17:30:31 2026 +0100
Create objects without prototypes when used as map with arbitrary keys
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index bd750f0..19ef3b0 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -42,7 +42,7 @@ function DocumentConversion(options, comments) {
function convertToHtml(document) {
var messages = [];
- var html = elementToHtml(document, messages, {});
+ var html = elementToHtml(document, messages, Object.create(null));
var deferredNodes = [];
walkHtml(html, function(node) {
@@ -50,7 +50,7 @@ function DocumentConversion(options, comments) {
deferredNodes.push(node);
}
});
- var deferredValues = {};
+ var deferredValues = Object.create(null);
return promises.mapSeries(deferredNodes, function(deferred) {
return deferred.value().then(function(value) {
deferredValues[deferred.id] = value;
diff --git a/lib/docx/content-types-reader.js b/lib/docx/content-types-reader.js
index 8233119..adb45a6 100644
--- a/lib/docx/content-types-reader.js
+++ b/lib/docx/content-types-reader.js
@@ -14,9 +14,9 @@ exports.defaultContentTypes = contentTypes({}, {});
function readContentTypesFromXml(element) {
- var extensionDefaults = {};
- var overrides = {};
-
+ var extensionDefaults = Object.create(null);
+ var overrides = Object.create(null);
+
element.children.forEach(function(child) {
if (child.name === "content-types:Default") {
extensionDefaults[child.attributes.Extension] = child.attributes.ContentType;
@@ -41,7 +41,7 @@ function contentTypes(overrides, extensionDefaults) {
} else {
var pathParts = path.split(".");
var extension = pathParts[pathParts.length - 1];
- if (extensionDefaults.hasOwnProperty(extension)) {
+ if (Object.prototype.hasOwnProperty.call(extensionDefaults, extension)) {
return extensionDefaults[extension];
} else {
var fallback = fallbackContentTypes[extension.toLowerCase()];
@@ -54,5 +54,5 @@ function contentTypes(overrides, extensionDefaults) {
}
}
};
-
+
}
diff --git a/lib/docx/numbering-xml.js b/lib/docx/numbering-xml.js
index 9c86536..c747609 100644
--- a/lib/docx/numbering-xml.js
+++ b/lib/docx/numbering-xml.js
@@ -17,7 +17,7 @@ function Numbering(nums, abstractNums, styles) {
);
function findLevel(numId, level) {
- return findLevelWithSeenNumIds(numId, level, {});
+ return findLevelWithSeenNumIds(numId, level, Object.create(null));
}
function findLevelWithSeenNumIds(numId, level, seenNumIds) {
@@ -63,7 +63,7 @@ function readNumberingXml(root, options) {
}
function readAbstractNums(root) {
- var abstractNums = {};
+ var abstractNums = Object.create(null);
root.getElementsByTagName("w:abstractNum").forEach(function(element) {
var id = element.attributes["w:abstractNumId"];
abstractNums[id] = readAbstractNum(element);
@@ -72,7 +72,7 @@ function readAbstractNums(root) {
}
function readAbstractNum(element) {
- var levels = {};
+ var levels = Object.create(null);
// Some malformed documents define numbering levels without an index, and
// reference the numbering using a w:numPr element without a w:ilvl child.
@@ -110,7 +110,7 @@ function readAbstractNum(element) {
}
function readNums(root) {
- var nums = {};
+ var nums = Object.create(null);
root.getElementsByTagName("w:num").forEach(function(element) {
var numId = element.attributes["w:numId"];
var abstractNumId = element.first("w:abstractNumId").attributes["w:val"];
diff --git a/lib/docx/relationships-reader.js b/lib/docx/relationships-reader.js
index 5f54f42..a3df9a9 100644
--- a/lib/docx/relationships-reader.js
+++ b/lib/docx/relationships-reader.js
@@ -19,12 +19,12 @@ function readRelationships(element) {
}
function Relationships(relationships) {
- var targetsByRelationshipId = {};
+ var targetsByRelationshipId = Object.create(null);
relationships.forEach(function(relationship) {
targetsByRelationshipId[relationship.relationshipId] = relationship.target;
});
- var targetsByType = {};
+ var targetsByType = Object.create(null);
relationships.forEach(function(relationship) {
if (!targetsByType[relationship.type]) {
targetsByType[relationship.type] = [];
diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js
index 276a668..1daa5e9 100644
--- a/lib/docx/styles-reader.js
+++ b/lib/docx/styles-reader.js
@@ -22,10 +22,10 @@ function Styles(paragraphStyles, characterStyles, tableStyles, numberingStyles)
Styles.EMPTY = new Styles({}, {}, {}, {});
function readStylesXml(root) {
- var paragraphStyles = {};
- var characterStyles = {};
- var tableStyles = {};
- var numberingStyles = {};
+ var paragraphStyles = Object.create(null);
+ var characterStyles = Object.create(null);
+ var tableStyles = Object.create(null);
+ var numberingStyles = Object.create(null);
root.getElementsByTagName("w:style").forEach(function(styleElement) {
var style = readStyleElement(styleElement);
diff --git a/lib/style-reader.js b/lib/style-reader.js
index 6305c59..4582e04 100644
--- a/lib/style-reader.js
+++ b/lib/style-reader.js
@@ -257,7 +257,7 @@ function htmlPathRule() {
capture(freshRule),
capture(separatorRule)
).map(function(tagName, attributesList, fresh, separator) {
- var attributes = {};
+ var attributes = Object.create(null);
var options = {};
attributesList.forEach(function(attribute) {
if (attribute.append && attributes[attribute.name]) {
diff --git a/lib/styles/html-paths.js b/lib/styles/html-paths.js
index 27bb777..757133f 100644
--- a/lib/styles/html-paths.js
+++ b/lib/styles/html-paths.js
@@ -38,7 +38,7 @@ function element(tagName, attributes, options) {
}
function Element(tagName, attributes, options) {
- var tagNames = {};
+ var tagNames = Object.create(null);
if (_.isArray(tagName)) {
tagName.forEach(function(tagName) {
tagNames[tagName] = true;
@@ -47,7 +47,7 @@ function Element(tagName, attributes, options) {
} else {
tagNames[tagName] = true;
}
-
+
this.tagName = tagName;
this.tagNames = tagNames;
this.attributes = attributes || {};
diff --git a/lib/xml/reader.js b/lib/xml/reader.js
index 41aabde..2797323 100644
--- a/lib/xml/reader.js
+++ b/lib/xml/reader.js
@@ -42,7 +42,7 @@ function readString(xmlString, namespaceMap) {
}
});
- var convertedAttributes = {};
+ var convertedAttributes = Object.create(null);
_.forEach(element.attributes, function(attribute) {
convertedAttributes[convertName(attribute)] = attribute.value;
});