Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2007 05:58:59 +0000 (05:58 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2007 05:58:59 +0000 (05:58 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=13107
        XPath should raise an exception when trying to parse an unknown function

        Test: fast/xpath/invalid-functions.html

        * xml/XPathFunctions.cpp:
        (WebCore::XPath::createFunction): Return 0 if the function couldn't be created.
        * xml/XPathGrammar.y: Handle nulls returned from createFunction().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@20338 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/xpath/invalid-functions-expected.txt [new file with mode: 0644]
LayoutTests/fast/xpath/invalid-functions.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/xml/XPathFunctions.cpp
WebCore/xml/XPathGrammar.y

index 5208f83..1abffc7 100644 (file)
@@ -1,3 +1,13 @@
+2007-03-19  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=13107
+        XPath should raise an exception when trying to parse an unknown function
+
+        * fast/xpath/invalid-functions-expected.txt: Added.
+        * fast/xpath/invalid-functions.html: Added.
+
 2007-03-19  Adele Peterson  <adele@apple.com>
 
         Reviewed by Beth.
diff --git a/LayoutTests/fast/xpath/invalid-functions-expected.txt b/LayoutTests/fast/xpath/invalid-functions-expected.txt
new file mode 100644 (file)
index 0000000..bd2ca10
--- /dev/null
@@ -0,0 +1,13 @@
+PASS document.createExpression("foobar()", null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.evaluate("foobar()", document, null, XPathResult.ANY_TYPE, null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.createExpression("position(//div)", null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.evaluate("position(//div)", document, null, XPathResult.ANY_TYPE, null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.createExpression("ceiling(1,2)", null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.evaluate("ceiling(1,2)", document, null, XPathResult.ANY_TYPE, null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.createExpression("ceiling(1,2)", null).evaluate(document, XPathResult.ANY_TYPE, null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.createExpression("boolean()", null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS document.evaluate("boolean()", document, null, XPathResult.ANY_TYPE, null) threw exception Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/xpath/invalid-functions.html b/LayoutTests/fast/xpath/invalid-functions.html
new file mode 100644 (file)
index 0000000..00cc995
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="console"></div>
+
+<script>
+    shouldThrow('document.createExpression("foobar()", null)');
+    shouldThrow('document.evaluate("foobar()", document, null, XPathResult.ANY_TYPE, null)');
+
+    shouldThrow('document.createExpression("position(//div)", null)');
+    shouldThrow('document.evaluate("position(//div)", document, null, XPathResult.ANY_TYPE, null)');
+
+    shouldThrow('document.createExpression("ceiling(1,2)", null)');
+    shouldThrow('document.evaluate("ceiling(1,2)", document, null, XPathResult.ANY_TYPE, null)');
+    shouldThrow('document.createExpression("ceiling(1,2)", null).evaluate(document, XPathResult.ANY_TYPE, null)');
+
+    shouldThrow('document.createExpression("boolean()", null)');
+    shouldThrow('document.evaluate("boolean()", document, null, XPathResult.ANY_TYPE, null)');
+
+    var successfullyParsed = true;
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 8c38f1b..a30cb06 100644 (file)
@@ -1,3 +1,16 @@
+2007-03-19  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        http://bugs.webkit.org/show_bug.cgi?id=13107
+        XPath should raise an exception when trying to parse an unknown function
+
+        Test: fast/xpath/invalid-functions.html
+
+        * xml/XPathFunctions.cpp:
+        (WebCore::XPath::createFunction): Return 0 if the function couldn't be created.
+        * xml/XPathGrammar.y: Handle nulls returned from createFunction().
+
 2007-03-19  Adele Peterson  <adele@apple.com>
 
         Reviewed by Beth.
index a4d5bff..c5003d7 100644 (file)
@@ -658,14 +658,8 @@ Function* createFunction(const String& name, const Vector<Expression*>& args)
     HashMap<String, FunctionRec>::iterator functionMapIter = functionMap->find(name);
     FunctionRec* functionRec = 0;
 
-    if (functionMapIter == functionMap->end() || !(functionRec = &functionMapIter->second)->args.contains(args.size())) {
-        deleteAllValues(args);
-
-        // Return a dummy function instead of 0.
-        Function* funcTrue = functionMap->get("true").factoryFn();
-        funcTrue->setName("true");
-        return funcTrue;
-    }
+    if (functionMapIter == functionMap->end() || !(functionRec = &functionMapIter->second)->args.contains(args.size()))
+        return 0;
 
     Function* function = functionRec->factoryFn();
     function->setArguments(args);
index bcaa0ab..9c891d7 100644 (file)
@@ -365,6 +365,8 @@ FunctionCall:
     FUNCTIONNAME '(' ')'
     {
         $$ = createFunction(*$1);
+        if (!$$)
+            YYABORT;
         PARSER->deleteString($1);
         PARSER->registerParseNode($$);
     }
@@ -372,6 +374,8 @@ FunctionCall:
     FUNCTIONNAME '(' ArgumentList ')'
     {
         $$ = createFunction(*$1, *$3);
+        if (!$$)
+            YYABORT;
         PARSER->deleteString($1);
         PARSER->deleteExpressionVector($3);
         PARSER->registerParseNode($$);