From c608d035569e16c81ea29ecf2a904e227379cecd Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Thu, 21 May 2015 21:14:15 +1000 Subject: styles names should be null by default --- lib/docx/styles-reader.js | 7 ++++++- tests/docx/styles-reader.tests.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js index dc90bc1..fec1cf2 100644 --- a/lib/docx/styles-reader.js +++ b/lib/docx/styles-reader.js @@ -36,6 +36,11 @@ function readStylesXml(xml) { function readStyleElement(styleElement) { var type = styleElement.attributes["w:type"]; var styleId = styleElement.attributes["w:styleId"]; - var name = styleElement.first("w:name").attributes["w:val"]; + var name = styleName(styleElement); return {type: type, styleId: styleId, name: name}; } + +function styleName(styleElement) { + var nameElement = styleElement.first("w:name"); + return nameElement ? nameElement.attributes["w:val"] : null; +} diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index 7899b1b..f76dfc2 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -59,6 +59,17 @@ describe('readStylesXml', function() { }); assert.equal(styles.findParagraphStyleById("Heading1").name, "Heading 1"); }); + + test('styles names should be null by default', function() { + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + paragraphStyleElement("Heading1", null), + characterStyleElement("Heading1Char", null) + ]) + }); + assert.equal(styles.findParagraphStyleById("Heading1Char"), null); + assert.equal(styles.findCharacterStyleById("Heading1"), null); + }); }); function paragraphStyleElement(id, name) { -- cgit v1.2.3