From 15a9243e0af7870737eca29a1e8b2ec6a4d9974f Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Wed, 2 Nov 2005 07:39:40 +0000 Subject: [PATCH] Bug 190628: Make some string-functions behave according to spec when second argument is an empty-string. r=Pike sr=peterv a=asa --- .../xslt/src/xpath/txStringFunctionCall.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/content/xslt/src/xpath/txStringFunctionCall.cpp b/content/xslt/src/xpath/txStringFunctionCall.cpp index cbd45695a52c..7d45d23130f3 100644 --- a/content/xslt/src/xpath/txStringFunctionCall.cpp +++ b/content/xslt/src/xpath/txStringFunctionCall.cpp @@ -72,8 +72,12 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) return new StringResult(NS_LITERAL_STRING("error")); nsAutoString arg1, arg2; - evaluateToString((Expr*)iter.next(), aContext, arg1); + Expr* arg1Expr = (Expr*)iter.next(); evaluateToString((Expr*)iter.next(), aContext, arg2); + if (arg2.IsEmpty()) + return new BooleanResult(PR_TRUE); + + evaluateToString(arg1Expr, aContext, arg1); return new BooleanResult(arg1.Find(arg2) >= 0); } case NORMALIZE_SPACE: @@ -116,8 +120,12 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) return new StringResult(NS_LITERAL_STRING("error")); nsAutoString arg1, arg2; - evaluateToString((Expr*)iter.next(), aContext, arg1); + Expr* arg1Expr = (Expr*)iter.next(); evaluateToString((Expr*)iter.next(), aContext, arg2); + if (arg2.IsEmpty()) + return new BooleanResult(PR_TRUE); + + evaluateToString(arg1Expr, aContext, arg1); return new BooleanResult(arg1.Find(arg2) == 0); } case STRING_LENGTH: @@ -182,6 +190,9 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) nsAutoString arg1, arg2; evaluateToString((Expr*)iter.next(), aContext, arg1); evaluateToString((Expr*)iter.next(), aContext, arg2); + if (arg2.IsEmpty()) + return new StringResult(arg1); + PRInt32 idx = arg1.Find(arg2); if (idx != kNotFound) { PRUint32 len = arg2.Length(); @@ -196,8 +207,13 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) return new StringResult(NS_LITERAL_STRING("error")); nsAutoString arg1, arg2; - evaluateToString((Expr*)iter.next(), aContext, arg1); + Expr* arg1Expr = (Expr*)iter.next(); evaluateToString((Expr*)iter.next(), aContext, arg2); + if (arg2.IsEmpty()) + return new StringResult(); + + evaluateToString(arg1Expr, aContext, arg1); + PRInt32 idx = arg1.Find(arg2); if (idx != kNotFound) { return new StringResult(Substring(arg1, 0, idx));