> However, I'm in doubt about the part that mangles path#fragment?query to 
> path?query. As specified by the URI RFC the fragment is always the last part 
> and anything after it can be disregarded. This would also make the patch a 
> lot simpler.

You are right. I misunderstood the fragment's position. I have
attached the updated patch (which also add a mention about this change
in the curl_easy_setopt manpage) and test case to match the URI RFC.

Thanks for the review!

Regards,
Julien
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
index 9229d09..a852028 100644
--- a/docs/libcurl/curl_easy_setopt.3
+++ b/docs/libcurl/curl_easy_setopt.3
@@ -449,6 +449,9 @@ on which protocols are supported.
 The string given to CURLOPT_URL must be url-encoded and follow RFC 2396
 (http://curl.haxx.se/rfc/rfc2396.txt).
 
+Please note that starting with version 7.20.0, the fragment part of the URI will
+not be send as part of the path, which was the case previously.
+
 \fICURLOPT_URL\fP is the only option that \fBmust\fP be set before
 \fIcurl_easy_perform(3)\fP is called.
 
diff --git a/lib/url.c b/lib/url.c
index aeb0f91..8a4525b 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -3311,8 +3311,9 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
                                     bool *prot_missing)
 {
   char *at;
-  char *tmp;
+  char *fragment;
   char *path = data->state.path;
+  char *query;
   int rc;
   char protobuf[16];
   const char *protop;
@@ -3438,11 +3439,11 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
    */
   at = strchr(conn->host.name, '@');
   if(at)
-    tmp = strchr(at+1, '?');
+    query = strchr(at+1, '?');
   else
-    tmp = strchr(conn->host.name, '?');
+    query = strchr(conn->host.name, '?');
 
-  if(tmp) {
+  if(query) {
     /* We must insert a slash before the '?'-letter in the URL. If the URL had
        a slash after the '?', that is where the path currently begins and the
        '?string' is still part of the host name.
@@ -3451,7 +3452,7 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
        the path. And have it all prefixed with a slash.
     */
 
-    size_t hostlen = strlen(tmp);
+    size_t hostlen = strlen(query);
     size_t pathlen = strlen(path);
 
     /* move the existing path plus the zero byte forward, to make room for
@@ -3459,11 +3460,11 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
     memmove(path+hostlen+1, path, pathlen+1);
 
      /* now copy the trailing host part in front of the existing path */
-    memcpy(path+1, tmp, hostlen);
+    memcpy(path+1, query, hostlen);
 
     path[0]='/'; /* prepend the missing slash */
 
-    *tmp=0; /* now cut off the hostname at the ? */
+    *query=0; /* now cut off the hostname at the ? */
   }
   else if(!path[0]) {
     /* if there's no path set, use a single slash */
@@ -3500,12 +3501,18 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
     }
   }
 
-  if (data->set.scope)
+  if(data->set.scope)
     /* Override any scope that was set above.  */
     conn->scope = data->set.scope;
 
+  /* Remove the fragment part of the path. Per RFC 2396, this is always the
+     last part of the URI. */
+  fragment = strrchr(path, '#');
+  if(fragment)
+    *fragment = 0;
+
   /*
-   * So if the URL was A://B/C,
+   * So if the URL was A://B/C#D,
    *   protop is A
    *   conn->host.name is B
    *   data->state.path is /C
diff --git a/tests/data/test1109 b/tests/data/test1109
new file mode 100644
index 0000000..6068380
--- /dev/null
+++ b/tests/data/test1109
@@ -0,0 +1,45 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+CURLOPT_URL
+</keywords>
+</info>
+
+# Server-side
+<reply name="1">
+<data>
+HTTP/1.1 200 OK
+Content-Length: 6
+
+hello
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP GET
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/1109#test
+</command>
+</client>
+
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET /1109 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/data/test1110 b/tests/data/test1110
new file mode 100644
index 0000000..70a9486
--- /dev/null
+++ b/tests/data/test1110
@@ -0,0 +1,45 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+CURLOPT_URL
+</keywords>
+</info>
+
+# Server-side
+<reply name="1">
+<data>
+HTTP/1.1 200 OK
+Content-Length: 6
+
+hello
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP GET
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/1110?q=foobar#fragment
+</command>
+</client>
+
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET /1110?q=foobar HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol>
+</verify>
+</testcase>

Attachment: test1110
Description: Binary data

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to