Julien Chaffraix fixed so that the fragment part in an URL is not sent to the server anymore
This commit is contained in:
4
CHANGES
4
CHANGES
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
Claes Jakobsson (6 Jan 2010)
|
||||||
|
- Julien Chaffraix fixed so that the fragment part in an URL is not sent
|
||||||
|
to the server anymore.
|
||||||
|
|
||||||
Kamil Dudka (3 Jan 2010)
|
Kamil Dudka (3 Jan 2010)
|
||||||
- Julien Chaffraix eliminated a duplicated initialization in singlesocket().
|
- Julien Chaffraix eliminated a duplicated initialization in singlesocket().
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ This release includes the following bugfixes:
|
|||||||
o some *_proxy environment variables didn't function
|
o some *_proxy environment variables didn't function
|
||||||
o libcurl-OpenSSL engine cleanup
|
o libcurl-OpenSSL engine cleanup
|
||||||
o header include fix for FreeBSD versions before v8
|
o header include fix for FreeBSD versions before v8
|
||||||
|
o fragment part of URLs are no longer sent to the server
|
||||||
|
|
||||||
This release includes the following known bugs:
|
This release includes the following known bugs:
|
||||||
|
|
||||||
|
|||||||
@@ -449,6 +449,9 @@ on which protocols are supported.
|
|||||||
The string given to CURLOPT_URL must be url-encoded and follow RFC 2396
|
The string given to CURLOPT_URL must be url-encoded and follow RFC 2396
|
||||||
(http://curl.haxx.se/rfc/rfc2396.txt).
|
(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
|
\fICURLOPT_URL\fP is the only option that \fBmust\fP be set before
|
||||||
\fIcurl_easy_perform(3)\fP is called.
|
\fIcurl_easy_perform(3)\fP is called.
|
||||||
|
|
||||||
|
|||||||
26
lib/url.c
26
lib/url.c
@@ -3311,8 +3311,9 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
bool *prot_missing)
|
bool *prot_missing)
|
||||||
{
|
{
|
||||||
char *at;
|
char *at;
|
||||||
char *tmp;
|
char *fragment;
|
||||||
char *path = data->state.path;
|
char *path = data->state.path;
|
||||||
|
char *query;
|
||||||
int rc;
|
int rc;
|
||||||
char protobuf[16];
|
char protobuf[16];
|
||||||
const char *protop;
|
const char *protop;
|
||||||
@@ -3438,11 +3439,11 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
*/
|
*/
|
||||||
at = strchr(conn->host.name, '@');
|
at = strchr(conn->host.name, '@');
|
||||||
if(at)
|
if(at)
|
||||||
tmp = strchr(at+1, '?');
|
query = strchr(at+1, '?');
|
||||||
else
|
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
|
/* 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
|
a slash after the '?', that is where the path currently begins and the
|
||||||
'?string' is still part of the host name.
|
'?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.
|
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);
|
size_t pathlen = strlen(path);
|
||||||
|
|
||||||
/* move the existing path plus the zero byte forward, to make room for
|
/* 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);
|
memmove(path+hostlen+1, path, pathlen+1);
|
||||||
|
|
||||||
/* now copy the trailing host part in front of the existing path */
|
/* 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 */
|
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]) {
|
else if(!path[0]) {
|
||||||
/* if there's no path set, use a single slash */
|
/* if there's no path set, use a single slash */
|
||||||
@@ -3500,12 +3501,19 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->set.scope)
|
if(data->set.scope)
|
||||||
/* Override any scope that was set above. */
|
/* Override any scope that was set above. */
|
||||||
conn->scope = data->set.scope;
|
conn->scope = data->set.scope;
|
||||||
|
|
||||||
|
/* Remove the fragment part of the path. Per RFC 2396, this is always the
|
||||||
|
last part of the URI. We are looking for the first '#' so that we deal gracefully
|
||||||
|
with non conformant URI such as http://example.com#foo#bar. */
|
||||||
|
fragment = strchr(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
|
* protop is A
|
||||||
* conn->host.name is B
|
* conn->host.name is B
|
||||||
* data->state.path is /C
|
* data->state.path is /C
|
||||||
|
|||||||
46
tests/data/test1109
Normal file
46
tests/data/test1109
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<testcase>
|
||||||
|
# Test that the fragment is not send as part of the path.
|
||||||
|
<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>
|
||||||
46
tests/data/test1110
Normal file
46
tests/data/test1110
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<testcase>
|
||||||
|
# Test that the fragment is not send as part of the path when the path contains a query.
|
||||||
|
<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>
|
||||||
46
tests/data/test1111
Normal file
46
tests/data/test1111
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<testcase>
|
||||||
|
# Test that no fragment is not send as part of the path when the URI contains 2 '#' (does not follow RFC 2396)
|
||||||
|
<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/1111?q=foobar#fragment#fragment2
|
||||||
|
</command>
|
||||||
|
</client>
|
||||||
|
|
||||||
|
|
||||||
|
# Verify data after the test has been "shot"
|
||||||
|
<verify>
|
||||||
|
<strip>
|
||||||
|
^User-Agent:.*
|
||||||
|
</strip>
|
||||||
|
<protocol>
|
||||||
|
GET /1111?q=foobar HTTP/1.1
|
||||||
|
Host: %HOSTIP:%HTTPPORT
|
||||||
|
Accept: */*
|
||||||
|
|
||||||
|
</protocol>
|
||||||
|
</verify>
|
||||||
|
</testcase>
|
||||||
Reference in New Issue
Block a user