Closed Bug 277777 (XPath-FCP) Opened 20 years ago Closed 20 years ago

Unevaluated XPath 2.0 expressions throwing errors

Categories

(Core :: XSLT, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: bugzilla, Assigned: sicking)

Details

(Keywords: testcase)

Attachments

(3 files, 3 obsolete files)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 XSLT 1.0 processors handling an XSLT 2.0 must not raise an error on unevaluated XPath expressions. Mozilla and family should not be halting on code like: <xsl:when test="system-property('xsl:version') >= 2"> <xsl:if test="some $x in ./* satisfies local-name(.)='bar'"> <p>bar exists</p> </xsl:if> </xsl:when> because the XPath 2.0 expression is wrapped such that Mozilla's XSLT 1.0 processor can never evaluate it. According to the XSLT spec, section 2.5: If an expression occurs in an attribute that is processed in forwards-compatible mode, then an XSLT processor must recover from errors in the expression as follows: * if the expression does not match the syntax allowed by the XPath grammar, then an error must not be signaled unless the expression is actually evaluated; Reproducible: Always Steps to Reproduce:
I'd like to see a testcase for this. See http://www.mozilla.org/projects/xslt/bug-reporting.html, Creating testcases.
Attached file XSL style sheet demonstrating bug (obsolete) —
Here's your test case.
Keywords: testcase
http://lxr.mozilla.org/seamonkey/source/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.cpp#194 is the culprit. We require that the expr is both optional and that it is in fcp. Jonas is our god of reading the fcp parts of the spec (and it is his code, too), I wonder what he thinks.
Ugh, it indeed seems like we're doing the wrong thing here. We're not supporting forwards compatible parsing of expressions well at all. Apparently I only did fcp of elements, not of expressions.
What we should do is to create an ErrorExpr that always throws an error (or just use txErrorFunctionCall). Then make getExprAttr and getAVTAttr return an instance of this when the parsing fails and fcp is enabled. Additionally we should set fnCall to a new txErrorFunctionCall at http://lxr.mozilla.org/mozilla/source/extensions/transformiix/source/xpath/ExprParser.cpp#553 when fcp is enabled. Both these things could be done always rather then when fcp is enabled if we wanted to.
Note that the current check in getAVTAttr and getExprAttr is correct. It is implementing the third bullet in the first list in section 2.5. An additional check is needed though to implement the first bullet in the second list.
Err, the change shouldn't be made in ExprParser since that'll make it impossible for extensions (like xslt) to implement extensions in the null namespace. But we should rather add code to txStylesheetCompilerState::resolveFunctionCall. That will also make it trivial to only do it in fcp mode.
Pike pointed out that we already take care of unrecongized functions. So all that's needed is the first paragraph of comment 6. Though I wonder if we handle unrecongized functions in a good way. The current solution makes us parse bad functions in DOM-XPath, though they'll fail when evaluated. Either we could push the txErrorFunctionCall creation to the resolveFunctionCall implementors, or we could add an inFCP() function to txIParseContext and only create the txErrorFunctionCall then. I think I like the latter better.
Alias: XPath-FCP
I have a patch in the works for this
Assignee: peterv → bugmail
Attached patch patch to fix (obsolete) — Splinter Review
Attachment #171765 - Flags: superreview?(peterv)
Attachment #171765 - Flags: review?(axel)
crap! my editor took it upon itself to do some whitespace cleanup. I won't check the ws only stuff in.
Correct logic of XPath 2.0 expression, though this doesn't affect demonstration of bug.
Attachment #170825 - Attachment is obsolete: true
Changed URL on stylesheet to revised stylesheet attachment.
Attachment #170826 - Attachment is obsolete: true
without whitespace 'cleanup's. Same otherwise
Attachment #171765 - Attachment is obsolete: true
Attachment #171821 - Flags: superreview?(peterv)
Attachment #171821 - Flags: review?(axel)
Attachment #171765 - Flags: superreview?(peterv)
Attachment #171765 - Flags: review?(axel)
Comment on attachment 171821 [details] [diff] [review] patch to fix v1.1 >Index: source/xslt/txStylesheetCompileHandlers.cpp >=================================================================== >@@ -214,15 +224,29 @@ getAVTAttr(txStylesheetAttr* aAttributes > aName, aRequired, &attr); > if (!attr) { > return rv; > } > > aAVT = txExprParser::createAttributeValueTemplate(attr->mValue, &aState); >- if (!aAVT && (aRequired || !aState.fcp())) { >- // XXX ErrorReport: XPath parse failure >- return NS_ERROR_XPATH_PARSE_FAILURE; >+ if (!aAVT) { >+ if (aRequired) { >+ } >+ else { >+ aAVT = nsnull; You can drop this, aAVT is already null. >--- /dev/null 2005-01-20 01:48:08.375000000 +0100 >+++ source/xpath/txErrorExpr.cpp 2005-01-19 16:59:09.718750000 +0100 >+ * Portions created by the Initial Developer are Copyright (C) 2002 2005
Attachment #171821 - Flags: superreview?(peterv) → superreview+
Attachment #171821 - Flags: review?(axel) → review+
check in, thanks for reviews
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Robin: please mark this bug verified if things now work as they should.
Works now in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b) Gecko/20050125. Marking verified.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: