Hi,

as suggested in http://curl.haxx.se/mail/lib-2009-04/0252.html, URL
fragment should not be send by libcURL.The attached patch corrects
this behaviour and renames a misnamed variable. I have tried the test
harness without regression.
2 new test cases are also attached separately thought they are part of
the global diff.

Comments are welcome!

Regards,
Julien
diff --git a/lib/url.c b/lib/url.c
index aeb0f91..c384426 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,15 +3501,28 @@ 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 if there is one! */
+  fragment = strrchr(path, '#');
+  if(fragment) {
+    query = strrchr(fragment, '?');
+    if(query) {
+      /* The path looks like foobar#fragment?query, we need to remove the fragment. */
+      memmove(fragment, query, strlen(query)+1); 
+    }
+    else
+      /* The path ends with a fragment so just cut it. */
+      *fragment = 0;
+  }
+
   /*
-   * So if the URL was A://B/C,
+   * So if the URL was A://B/C#D?E,
    *   protop is A
    *   conn->host.name is B
-   *   data->state.path is /C
+   *   data->state.path is /C?E
    */
 
   return findprotocol(data, conn, protop);
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..b0a515f
--- /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#test?q=foobar
+</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: test1109
Description: Binary data

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