Skip to content

Commit

Permalink
Ignore w:u elements when w:val is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Mar 9, 2022
1 parent 76cb8e7 commit 52ec8fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.4.21

* Ignore w:u elements when w:val is missing.

# 1.4.20

* Emit warning instead of throwing exception when image file cannot be found for
Expand Down
2 changes: 1 addition & 1 deletion lib/docx/body-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function BodyReader(options) {
function readUnderline(element) {
if (element) {
var value = element.attributes["w:val"];
return value !== "false" && value !== "0" && value !== "none";
return value !== undefined && value !== "false" && value !== "0" && value !== "none";
} else {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions test/docx/body-reader.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ test("isUnderline is false if underline element is not present", function() {
assert.deepEqual(run.isUnderline, false);
});

test("isUnderline is true if underline element is present without w:val attribute", function() {
test("isUnderline is false if underline element is present without w:val attribute", function() {
var underlineXml = new XmlElement("w:u");
var runXml = runWithProperties([underlineXml]);
var run = readXmlElementValue(runXml);
assert.equal(run.isUnderline, true);
assert.equal(run.isUnderline, false);
});

test("isUnderline is false if underline element is present and w:val is false", function() {
Expand All @@ -540,7 +540,7 @@ test("isUnderline is false if underline element is present and w:val is none", f
assert.equal(run.isUnderline, false);
});

test("isUnderline is false if underline element is present and w:val is not none or falsy", function() {
test("isUnderline is true if underline element is present and w:val is not none or falsy", function() {
var underlineXml = new XmlElement("w:u", {"w:val": "single"});
var runXml = runWithProperties([underlineXml]);
var run = readXmlElementValue(runXml);
Expand Down

0 comments on commit 52ec8fb

Please sign in to comment.