diff --git a/src/core/xfa/bind.js b/src/core/xfa/bind.js index b73e6bf0b..32f58d54e 100644 --- a/src/core/xfa/bind.js +++ b/src/core/xfa/bind.js @@ -545,6 +545,12 @@ class Binder { // to have something to match with the given expression. // See http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=199 match = createDataNode(this.data, dataNode, ref); + if (!match) { + // For example if the node contains a .(...) then it isn't + // findable. + // TODO: remove this when .(...) is implemented. + continue; + } if (this._isConsumeData()) { match[$consumed] = true; } diff --git a/src/core/xfa/som.js b/src/core/xfa/som.js index 472b8306d..515b69671 100644 --- a/src/core/xfa/som.js +++ b/src/core/xfa/som.js @@ -60,7 +60,10 @@ function parseIndex(index) { return parseInt(index, 10) || 0; } -function parseExpression(expr, dotDotAllowed) { +// For now expressions containaing .[...] or .(...) are not +// evaluated so don't parse them. +// TODO: implement that stuff and the remove the noExpr param. +function parseExpression(expr, dotDotAllowed, noExpr = true) { let match = expr.match(namePattern); if (!match) { return null; @@ -108,10 +111,22 @@ function parseExpression(expr, dotDotAllowed) { operator = operators.dotHash; break; case "[": + if (noExpr) { + warn( + "XFA - SOM expression contains a FormCalc subexpression which is not supported for now." + ); + return null; + } // TODO: FormCalc expression so need to use the parser operator = operators.dotBracket; break; case "(": + if (noExpr) { + warn( + "XFA - SOM expression contains a JavaScript subexpression which is not supported for now." + ); + return null; + } // TODO: // Javascript expression: should be a boolean operation with a path // so maybe we can have our own parser for that stuff or diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index a97a9b2fe..71174f29b 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -172,6 +172,9 @@ function handleBreak(node) { let target = null; if (node.target) { target = root[$searchNode](node.target, node[$getParent]()); + if (!target) { + return false; + } target = target ? target[0] : target; } @@ -197,12 +200,12 @@ function handleBreak(node) { target = null; } - const pageArea = target[$getParent](); - const contentAreas = pageArea.contentArea.children; + const pageArea = target && target[$getParent](); let index; if (node.startNew) { if (target) { + const contentAreas = pageArea.contentArea.children; index = contentAreas.findIndex(e => e === target) - 1; } else { index = currentPageArea.contentArea.children.findIndex( @@ -210,6 +213,7 @@ function handleBreak(node) { ); } } else if (target && target !== currentContentArea) { + const contentAreas = pageArea.contentArea.children; index = contentAreas.findIndex(e => e === target) - 1; } else { return false; diff --git a/test/pdfs/xfa_bug1717668_4.pdf.link b/test/pdfs/xfa_bug1717668_4.pdf.link new file mode 100644 index 000000000..c972db6d0 --- /dev/null +++ b/test/pdfs/xfa_bug1717668_4.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=9229381 diff --git a/test/test_manifest.json b/test/test_manifest.json index 68412257e..9183c35d0 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -994,7 +994,7 @@ "enableXfa": true, "type": "eq" }, - { "id": "xfa_bug17176688_1", + { "id": "xfa_bug1717668_1", "file": "pdfs/xfa_bug1717668_1.pdf", "md5": "564ecff67be690b43c2a144ae5967034", "link": true, @@ -1002,7 +1002,7 @@ "enableXfa": true, "type": "eq" }, - { "id": "xfa_bug17176688_2", + { "id": "xfa_bug1717668_2", "file": "pdfs/xfa_bug1717668_2.pdf", "md5": "08aa8bf9fec5aa7b8ff13d9ba72ca8ac", "link": true, @@ -1010,7 +1010,7 @@ "enableXfa": true, "type": "eq" }, - { "id": "xfa_bug17176688_3", + { "id": "xfa_bug1717668_3", "file": "pdfs/xfa_bug1717668_3.pdf", "md5": "4ff2531dbefebabc3f128d4ae20552a4", "link": true, @@ -1018,6 +1018,14 @@ "enableXfa": true, "type": "eq" }, + { "id": "xfa_bug1717668_4", + "file": "pdfs/xfa_bug1717668_4.pdf", + "md5": "1c3dc4873ad6b84adb164ed69ed202f5", + "link": true, + "rounds": 1, + "enableXfa": true, + "type": "eq" + }, { "id": "xfa_bug1718037", "file": "pdfs/xfa_bug1718037.pdf", "md5": "a0b53d50e9faed9d57950a5159d5da12",