diff options
| -rw-r--r-- | lib/docx/body-reader.js | 2 | ||||
| -rw-r--r-- | test/docx/body-reader.tests.js | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 94034d1..23c6a20 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -60,7 +60,7 @@ function BodyReader(options) { return readRunStyle(element).map(function(style) { var fontSizeString = element.firstOrEmpty("w:sz").attributes["w:val"]; // w:sz gives the font size in half points, so halve the value to get the size in points - var fontSize = fontSizeString ? parseInt(fontSizeString, 10) / 2 : null; + var fontSize = /^[0-9]+$/.test(fontSizeString) ? parseInt(fontSizeString, 10) / 2 : null; return { type: "runProperties", diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index 73c8647..1260575 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -580,6 +580,14 @@ test("run has fontSize read from properties", function() { assert.deepEqual(run.fontSize, 14); }); +test("run with invalid w:sz has null font size", function() { + var fontSizeXml = new XmlElement("w:sz", {"w:val": "28a"}); + var runXml = runWithProperties([fontSizeXml]); + + var run = readXmlElementValue(runXml); + assert.deepEqual(run.fontSize, null); +}); + test("run properties not included as child of run", function() { var runStyleXml = new XmlElement("w:rStyle"); var runPropertiesXml = new XmlElement("w:rPr", {}, [runStyleXml]); |
