diff --git a/lib/url.c b/lib/url.c
index 4bc82a65fa7f73f278439623f0769de724d50185..b3fc74884b87c8c5ace79a348e5fed3a3063b3ed 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -3733,6 +3733,18 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
       }
     }
 
+    char *path_q_sep = strchr(path, '?');
+    if(path_q_sep) {
+      /* according to rfc3986, allow the query (?foo=bar) and frament(#foobar)
+         also on file:// urls
+
+        cut the string-part after '?' (beause the query-str is useless for us)
+         */
+
+      /* terminate the string */
+      path_q_sep[0] = 0;
+    }
+
     protop = "file"; /* protocol string */
   }
   else {
diff --git a/tests/data/test219 b/tests/data/test219
new file mode 100644
index 0000000000000000000000000000000000000000..a2783f9080706a70831f322361df9100e6c67971
--- /dev/null
+++ b/tests/data/test219
@@ -0,0 +1,30 @@
+<testcase>
+# Server-side
+<reply>
+<data>
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+file
+</server>
+ <name>
+two file:// URLs to stdout
+ </name>
+ <command>
+file://localhost/%PWD/log/test202.txt?a_query=foobar#afragment
+</command>
+<file name="log/test202.txt">
+contents in a single file
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<stdout>
+contents in a single file
+</stdout>
+</verify>
+</testcase>

