Bug 277777: Fix forwards compatible parsing of expressions in XSLT and be more strict about parsing of functioncalls in DOM-XPath.
r=pike sr=peterv
This commit is contained in:
Родитель
e0f6ad84a1
Коммит
4c92fb6059
|
@ -132,4 +132,7 @@
|
|||
#define NS_ERROR_XSLT_LOAD_BLOCKED_ERROR \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XSLT, 27)
|
||||
|
||||
#define NS_ERROR_XPATH_INVALID_EXPRESSION_EVALUATED \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XSLT, 28)
|
||||
|
||||
#endif // __TX_ERROR
|
||||
|
|
|
@ -81,6 +81,7 @@ CPPSRCS = AdditiveExpr.cpp \
|
|||
RootExpr.cpp \
|
||||
StringFunctionCall.cpp \
|
||||
StringResult.cpp \
|
||||
txErrorExpr.cpp \
|
||||
txLiteralExpr.cpp \
|
||||
txNameTest.cpp \
|
||||
txNodeSet.cpp \
|
||||
|
|
|
@ -204,6 +204,11 @@ PRBool nsXPathEvaluator::ParseContextImpl::caseInsensitiveNameTests()
|
|||
return !mIsCaseSensitive;
|
||||
}
|
||||
|
||||
PRBool nsXPathEvaluator::ParseContextImpl::fcp()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
nsXPathEvaluator::ParseContextImpl::SetErrorOffset(PRUint32 aOffset)
|
||||
{
|
||||
|
|
|
@ -92,6 +92,7 @@ private:
|
|||
nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID,
|
||||
FunctionCall*& aFunction);
|
||||
PRBool caseInsensitiveNameTests();
|
||||
PRBool fcp();
|
||||
void SetErrorOffset(PRUint32 aOffset);
|
||||
|
||||
private:
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is TransforMiiX XSLT processor code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Jonas Sicking.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jonas Sicking <jonas@sicking.cc> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txError.h"
|
||||
#include "Expr.h"
|
||||
#include "nsString.h"
|
||||
#include "txIXPathContext.h"
|
||||
|
||||
nsresult
|
||||
txErrorExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
nsAutoString err(NS_LITERAL_STRING("Invalid expression evaluated"));
|
||||
#ifdef TX_TO_STRING
|
||||
err.AppendLiteral(": ");
|
||||
toString(err);
|
||||
#endif
|
||||
aContext->receiveError(err,
|
||||
NS_ERROR_XPATH_INVALID_EXPRESSION_EVALUATED);
|
||||
|
||||
return NS_ERROR_XPATH_INVALID_EXPRESSION_EVALUATED;
|
||||
}
|
||||
|
||||
#ifdef TX_TO_STRING
|
||||
void
|
||||
txErrorExpr::toString(nsAString& aStr)
|
||||
{
|
||||
aStr.Append(mStr);
|
||||
}
|
||||
#endif
|
|
@ -44,6 +44,7 @@
|
|||
#include "List.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "txCore.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TX_TO_STRING
|
||||
|
@ -716,6 +717,27 @@ private:
|
|||
|
||||
}; //-- UnionExpr
|
||||
|
||||
/**
|
||||
* Expression that failed to parse
|
||||
*/
|
||||
class txErrorExpr : public Expr
|
||||
{
|
||||
public:
|
||||
#ifdef TX_TO_STRING
|
||||
txErrorExpr(const nsAString& aStr)
|
||||
: mStr(aStr)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
TX_DECL_EXPR;
|
||||
|
||||
#ifdef TX_TO_STRING
|
||||
private:
|
||||
nsString mStr;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -575,7 +575,7 @@ txExprParser::createFunctionCall(txExprLexer& lexer, txIParseContext* aContext,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (rv == NS_ERROR_XPATH_UNKNOWN_FUNCTION) {
|
||||
if (rv == NS_ERROR_XPATH_UNKNOWN_FUNCTION && aContext->fcp()) {
|
||||
// Don't throw parse error, just error on evaluation
|
||||
fnCall = new txErrorFunctionCall(lName, namespaceID);
|
||||
NS_ENSURE_TRUE(fnCall, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
|
|
@ -80,6 +80,11 @@ public:
|
|||
*/
|
||||
virtual PRBool caseInsensitiveNameTests() = 0;
|
||||
|
||||
/**
|
||||
* Should the expression be parsed in forwards compatible parsing mode
|
||||
*/
|
||||
virtual PRBool fcp() = 0;
|
||||
|
||||
/*
|
||||
* Callback to be used by the Parser if errors are detected.
|
||||
*/
|
||||
|
|
|
@ -191,9 +191,19 @@ getExprAttr(txStylesheetAttr* aAttributes,
|
|||
|
||||
rv = txExprParser::createExpr(attr->mValue, &aState,
|
||||
getter_Transfers(aExpr));
|
||||
if (NS_FAILED(rv) && !aRequired && aState.fcp()) {
|
||||
if (NS_FAILED(rv) && aState.fcp()) {
|
||||
// use default value in fcp for not required exprs
|
||||
aExpr = nsnull;
|
||||
if (aRequired) {
|
||||
aExpr = new txErrorExpr(
|
||||
#ifdef TX_TO_STRING
|
||||
attr->mValue
|
||||
#endif
|
||||
);
|
||||
NS_ENSURE_TRUE(aExpr, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
aExpr = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -217,9 +227,20 @@ getAVTAttr(txStylesheetAttr* aAttributes,
|
|||
}
|
||||
|
||||
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 (!aState.fcp()) {
|
||||
// XXX ErrorReport: XPath parse failure
|
||||
return NS_ERROR_XPATH_PARSE_FAILURE;
|
||||
}
|
||||
|
||||
if (aRequired) {
|
||||
aAVT = new txErrorExpr(
|
||||
#ifdef TX_TO_STRING
|
||||
attr->mValue
|
||||
#endif
|
||||
);
|
||||
NS_ENSURE_TRUE(aAVT, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -702,12 +702,6 @@ txStylesheetCompilerState::popPtr()
|
|||
return value;
|
||||
}
|
||||
|
||||
MBool
|
||||
txStylesheetCompilerState::fcp()
|
||||
{
|
||||
return mElementContext->mForwardsCompatibleParsing;
|
||||
}
|
||||
|
||||
nsresult
|
||||
txStylesheetCompilerState::addToplevelItem(txToplevelItem* aItem)
|
||||
{
|
||||
|
@ -935,6 +929,12 @@ txStylesheetCompilerState::caseInsensitiveNameTests()
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
txStylesheetCompilerState::fcp()
|
||||
{
|
||||
return mElementContext->mForwardsCompatibleParsing;
|
||||
}
|
||||
|
||||
void
|
||||
txStylesheetCompilerState::SetErrorOffset(PRUint32 aOffset)
|
||||
{
|
||||
|
|
|
@ -124,9 +124,6 @@ public:
|
|||
nsresult pushPtr(void* aPtr);
|
||||
void* popPtr();
|
||||
|
||||
// State-checking functions
|
||||
MBool fcp();
|
||||
|
||||
// stylesheet functions
|
||||
nsresult addToplevelItem(txToplevelItem* aItem);
|
||||
nsresult openInstructionContainer(txInstructionContainer* aContainer);
|
||||
|
@ -145,6 +142,7 @@ public:
|
|||
nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID,
|
||||
FunctionCall*& aFunction);
|
||||
PRBool caseInsensitiveNameTests();
|
||||
PRBool fcp();
|
||||
void SetErrorOffset(PRUint32 aOffset);
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче