diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c index a0ae58f223..0277657526 100644 --- a/src/tool_operhlp.c +++ b/src/tool_operhlp.c @@ -198,19 +198,19 @@ CURLcode get_url_file_name(char **filename, const char *url, SANITIZEcode *sc) curl_url_cleanup(uh); uh = NULL; if(!uerr) { - int i; char *pc = NULL, *pc2 = NULL; - for(i = 0; i < 2; i++) { + do { pc = strrchr(path, '/'); pc2 = strrchr(pc ? pc + 1 : path, '\\'); if(pc2) pc = pc2; - if(pc && !pc[1] && !i) { + if(pc && !pc[1]) /* if the path ends with slash, try removing the trailing one and get the last directory part */ *pc = 0; - } - } + else + break; + } while(1); if(pc) { /* duplicate the string beyond the slash */ diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 44473ecfa3..c080c32133 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -217,8 +217,7 @@ test1614 test1615 test1616 test1617 test1618 test1619 test1620 test1621 \ test1622 test1623 test1624 test1625 test1626 test1627 \ \ test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 \ -test1638 \ -test1640 test1641 test1642 test1643 \ +test1638 test1639 test1640 test1641 test1642 test1643 test1644 \ \ test1650 test1651 test1652 test1653 test1654 test1655 test1656 test1657 \ test1658 test1659 test1660 test1661 test1662 test1663 test1664 test1665 \ diff --git a/tests/data/test1639 b/tests/data/test1639 new file mode 100644 index 0000000000..d171c3dc23 --- /dev/null +++ b/tests/data/test1639 @@ -0,0 +1,65 @@ + + + + +HTTP +HTTP GET + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT +ETag: "21025-dc7-39462498" +Accept-Ranges: bytes +Content-Length: 6 +Connection: close +Content-Type: text/html +Funny-head: yesyes + +-foo- + + + +# Client-side + + +http + + +-O with URL without path using many trailing slashes + + +http://%HOSTIP:%HTTPPORT///////////////// -O --output-dir %LOGDIR + + + +# Verify data after the test has been "shot" + + +GET ///////////////// HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT +ETag: "21025-dc7-39462498" +Accept-Ranges: bytes +Content-Length: 6 +Connection: close +Content-Type: text/html +Funny-head: yesyes + +-foo- + + + diff --git a/tests/data/test1644 b/tests/data/test1644 new file mode 100644 index 0000000000..14cd7cec7f --- /dev/null +++ b/tests/data/test1644 @@ -0,0 +1,65 @@ + + + + +HTTP +HTTP GET + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT +ETag: "21025-dc7-39462498" +Accept-Ranges: bytes +Content-Length: 6 +Connection: close +Content-Type: text/html +Funny-head: yesyes + +-foo- + + + +# Client-side + + +http + + +-O with URL with path but using many trailing slashes + + +http://%HOSTIP:%HTTPPORT///foo////////////// -O --output-dir %LOGDIR + + + +# Verify data after the test has been "shot" + + +GET ///foo////////////// HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT +ETag: "21025-dc7-39462498" +Accept-Ranges: bytes +Content-Length: 6 +Connection: close +Content-Type: text/html +Funny-head: yesyes + +-foo- + + +