Title: [226028] releases/WebKitGTK/webkit-2.18/Source/WebDriver
Revision
226028
Author
carlo...@webkit.org
Date
2017-12-18 03:47:44 -0800 (Mon, 18 Dec 2017)

Log Message

Merge r225083 - WebDriver: do not try to parse http body if method is not POST
https://bugs.webkit.org/show_bug.cgi?id=179918

Reviewed by Darin Adler.

As said in the spec:

  5. If request’s method is POST:

    1. Let parse result be the result of parsing as JSON with request’s body as the argument. If this process
       throws an exception, return an error with error code invalid argument and jump back to step 1 in this
       overall algorithm.

    2. If parse result is not an Object, send an error with error code invalid argument and jump back to step 1
       in this overall algorithm.

    Otherwise, let parameters be parse result.

  Otherwise, let parameters be null.

6.3 Processing Model
https://w3c.github.io/webdriver/webdriver-spec.html#processing-model

Now, w3c tests are sending null as body of delete session command (it used to be just empty), making it fail
with invalid argument error.

* WebDriverService.cpp:
(WebDriver::WebDriverService::findCommand):
(WebDriver::WebDriverService::handleRequest):
* WebDriverService.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog (226027 => 226028)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog	2017-12-18 11:47:40 UTC (rev 226027)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog	2017-12-18 11:47:44 UTC (rev 226028)
@@ -1,5 +1,38 @@
 2017-11-21  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        WebDriver: do not try to parse http body if method is not POST
+        https://bugs.webkit.org/show_bug.cgi?id=179918
+
+        Reviewed by Darin Adler.
+
+        As said in the spec:
+
+          5. If request’s method is POST:
+
+            1. Let parse result be the result of parsing as JSON with request’s body as the argument. If this process
+               throws an exception, return an error with error code invalid argument and jump back to step 1 in this
+               overall algorithm.
+
+            2. If parse result is not an Object, send an error with error code invalid argument and jump back to step 1
+               in this overall algorithm.
+
+            Otherwise, let parameters be parse result.
+
+          Otherwise, let parameters be null.
+
+        6.3 Processing Model
+        https://w3c.github.io/webdriver/webdriver-spec.html#processing-model
+
+        Now, w3c tests are sending null as body of delete session command (it used to be just empty), making it fail
+        with invalid argument error.
+
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::findCommand):
+        (WebDriver::WebDriverService::handleRequest):
+        * WebDriverService.h:
+
+2017-11-21  Carlos Garcia Campos  <cgar...@igalia.com>
+
         WebDriver: crash in Session::computeElementLayout when called without a current browsing context
         https://bugs.webkit.org/show_bug.cgi?id=179917
 

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp (226027 => 226028)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp	2017-12-18 11:47:40 UTC (rev 226027)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp	2017-12-18 11:47:44 UTC (rev 226028)
@@ -174,15 +174,11 @@
     return std::nullopt;
 }
 
-bool WebDriverService::findCommand(const String& method, const String& path, CommandHandler* handler, HashMap<String, String>& parameters)
+bool WebDriverService::findCommand(HTTPMethod method, const String& path, CommandHandler* handler, HashMap<String, String>& parameters)
 {
-    auto commandMethod = toCommandHTTPMethod(method);
-    if (!commandMethod)
-        return false;
-
     size_t length = WTF_ARRAY_LENGTH(s_commands);
     for (size_t i = 0; i < length; ++i) {
-        if (s_commands[i].method != *commandMethod)
+        if (s_commands[i].method != method)
             continue;
 
         Vector<String> pathTokens;
@@ -213,15 +209,20 @@
 
 void WebDriverService::handleRequest(HTTPRequestHandler::Request&& request, Function<void (HTTPRequestHandler::Response&&)>&& replyHandler)
 {
+    auto method = toCommandHTTPMethod(request.method);
+    if (!method) {
+        sendResponse(WTFMove(replyHandler), CommandResult::fail(CommandResult::ErrorCode::UnknownCommand, String("Unknown method: " + request.method)));
+        return;
+    }
     CommandHandler handler;
     HashMap<String, String> parameters;
-    if (!findCommand(request.method, request.path, &handler, parameters)) {
+    if (!findCommand(method.value(), request.path, &handler, parameters)) {
         sendResponse(WTFMove(replyHandler), CommandResult::fail(CommandResult::ErrorCode::UnknownCommand, String("Unknown command: " + request.path)));
         return;
     }
 
     RefPtr<InspectorObject> parametersObject;
-    if (request.dataLength) {
+    if (method.value() == HTTPMethod::Post && request.dataLength) {
         RefPtr<InspectorValue> messageValue;
         if (!InspectorValue::parseJSON(String::fromUTF8(request.data, request.dataLength), messageValue)) {
             sendResponse(WTFMove(replyHandler), CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));

Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h (226027 => 226028)


--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h	2017-12-18 11:47:40 UTC (rev 226027)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h	2017-12-18 11:47:44 UTC (rev 226028)
@@ -62,7 +62,7 @@
     static const Command s_commands[];
 
     static std::optional<HTTPMethod> toCommandHTTPMethod(const String& method);
-    static bool findCommand(const String& method, const String& path, CommandHandler*, HashMap<String, String>& parameters);
+    static bool findCommand(HTTPMethod, const String& path, CommandHandler*, HashMap<String, String>& parameters);
 
     void newSession(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
     void deleteSession(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to