diff --git a/src/display/xfa_layer.js b/src/display/xfa_layer.js index 802634844..9f713edbe 100644 --- a/src/display/xfa_layer.js +++ b/src/display/xfa_layer.js @@ -176,8 +176,8 @@ class XfaLayer { linkService, }); } - const stack = [[root, -1, rootHtml]]; + const isNotForRichText = intent !== "richText"; const rootDiv = parameters.div; rootDiv.append(rootHtml); @@ -187,13 +187,28 @@ class XfaLayer { } // Set defaults. - if (intent !== "richText") { + if (isNotForRichText) { rootDiv.setAttribute("class", "xfaLayer xfaFont"); } // Text nodes used for the text highlighter. const textDivs = []; + // In the rich text context, it's possible to just have a text node without + // a root element, so we handle this case here (see issue 17215). + if (root.children.length === 0) { + if (root.value) { + const node = document.createTextNode(root.value); + rootHtml.append(node); + if (isNotForRichText && XfaText.shouldBuildText(root.name)) { + textDivs.push(node); + } + } + return { textDivs }; + } + + const stack = [[root, -1, rootHtml]]; + while (stack.length > 0) { const [parent, i, html] = stack.at(-1); if (i + 1 === parent.children.length) { @@ -233,7 +248,7 @@ class XfaLayer { stack.push([child, -1, childHtml]); } else if (child.value) { const node = document.createTextNode(child.value); - if (XfaText.shouldBuildText(name)) { + if (isNotForRichText && XfaText.shouldBuildText(name)) { textDivs.push(node); } childHtml.append(node); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 3eff1fe26..4101b2eb0 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -617,3 +617,5 @@ !bug1851498.pdf !issue17065.pdf !issue17069.pdf +!issue17215.pdf + diff --git a/test/pdfs/issue17215.pdf b/test/pdfs/issue17215.pdf new file mode 100755 index 000000000..d50846ade Binary files /dev/null and b/test/pdfs/issue17215.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index bcd70169b..4035622bf 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -8189,5 +8189,13 @@ "link": true, "rounds": 1, "type": "eq" - } + }, + { + "id": "issue17215-annotations", + "file": "pdfs/issue17215.pdf", + "md5": "968848af6ef593a3d1d6aba030ef47cb", + "rounds": 1, + "type": "eq", + "annotations": true + } ]