[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ./ChangeLog libbase/URL.cpp libbase/URL.h...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ./ChangeLog libbase/URL.cpp libbase/URL.h... |
Date: |
Sun, 14 May 2006 22:47:01 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch:
Changes by: Sandro Santilli <address@hidden> 06/05/14 22:47:01
Modified files:
. : ChangeLog
libbase : URL.cpp URL.h
testsuite/libbase: Makefile.am URLTest.cpp
Log message:
* libbase/URL.{cpp,h}: handling of relative paths containing
"../" components, handling of CWD-relative paths.
* testsuite/libbase/URLTest.cpp: tests for "../"
components in relative paths.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.317&tr2=1.318&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/libbase/URL.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/libbase/URL.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/testsuite/libbase/Makefile.am.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/testsuite/libbase/URLTest.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.317 gnash/ChangeLog:1.318
--- gnash/ChangeLog:1.317 Sat May 13 22:34:14 2006
+++ gnash/ChangeLog Sun May 14 22:47:01 2006
@@ -1,3 +1,10 @@
+2006-05-14 Sandro Santilli <address@hidden>
+
+ * libbase/URL.{cpp,h}: handling of relative paths containing
+ "../" components, handling of CWD-relative paths.
+ * testsuite/libbase/URLTest.cpp: tests for "../"
+ components in relative paths.
+
2006-05-13 Stefan Schweizer <address@hidden>
* libbase/Makefile.am: add CURL_LIBS and OPENGL_LIBS
Index: gnash/libbase/URL.cpp
diff -u gnash/libbase/URL.cpp:1.3 gnash/libbase/URL.cpp:1.4
--- gnash/libbase/URL.cpp:1.3 Sat May 13 22:45:47 2006
+++ gnash/libbase/URL.cpp Sun May 14 22:47:01 2006
@@ -47,17 +47,20 @@
#include <cstring>
#include <stdexcept>
#include <cassert>
+#include <algorithm>
// these are for stat(2)
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <limits.h>
+
namespace gnash {
/*private*/
void
-URL::init(const char* in)
+URL::init_absolute(const char* in)
{
size_t len = strlen(in);
const char* last = in+len;
@@ -96,6 +99,8 @@
_proto = "file";
}
+ assert ( *in == '/' );
+
// What remains now is a path
_path.assign(in, last-in);
}
@@ -103,21 +108,70 @@
/*public*/
URL::URL(const std::string& absolute_url)
{
- init(absolute_url.c_str());
+ //std::cerr << "URL(" << absolute_url << ")" << std::endl;
+ if ( absolute_url[0] == '/'
+ || absolute_url.find("://") != std::string::npos )
+ {
+ //std::cerr << "It's absolute" << std::endl;
+ init_absolute(absolute_url.c_str());
+ }
+ else
+ {
+ //std::cerr << "It's relative" << std::endl;
+ char buf[PATH_MAX+1];
+ getcwd(buf, PATH_MAX);
+ char* ptr = buf+strlen(buf);
+ *ptr++ = '/';
+ *ptr = '\0';
+ URL cwd(buf);
+ init_relative(absolute_url, cwd);
+ }
+}
+
+struct DupSlashes
+{
+ bool operator() (char a, char b) const
+ {
+ return ( a == '/' && b == '/' );
+ }
+};
+
+/*private static*/
+std::string
+URL::normalize_path(const std::string& path)
+{
+ std::string ret;
+ ret.resize(path.size());
+ // remove duplicated slashes
+ std::unique_copy(path.begin(), path.end(),
+ ret.begin(), DupSlashes());
+ return ret;
}
/*public*/
URL::URL(const std::string& relative_url, const URL& baseurl)
{
- const char* in = relative_url.c_str();
+ init_relative(relative_url, baseurl);
+}
+
+/*private*/
+void
+URL::init_relative(const std::string& relative_url, const URL& baseurl)
+{
+ // WARNING!, we're removing :// component!
+ std::string normalized_relative = normalize_path(relative_url);
+
+ const char* in = normalized_relative.c_str();
// If has a protocol, call absolute_url ctor
if ( strstr(in, "://") )
{
- init(in);
+ init_absolute(in);
return;
}
+//fprintf(stderr, " input=%s\n", in);
+
// use protocol and host from baseurl
_proto = baseurl._proto;
_host = baseurl._host;
@@ -130,11 +184,46 @@
else // path-relative
{
- // get dirname from basurl path
- _path = baseurl._path.substr(
- 0,
+
+
+ // see how many dirs we want to take
+ // off the baseurl path
+ int dirsback=0;
+ while ( char* ptr = strstr(in, "../") )
+ {
+ ++dirsback;
+ in = ptr+3;
+ }
+
+//fprintf(stderr, "dirsback=%d, in=%s\n", dirsback, in);
+
+ // find dirsback'th slash from end of
+ // baseurl path
+ std::string basedir = baseurl._path.substr(0,
baseurl._path.find_last_of("/")+1);
- _path += relative_url;
+
+//fprintf(stderr, "basedir=%s\n", basedir.c_str());
+
+ assert(basedir[0] == '/');
+ assert(*(basedir.rbegin()) == '/');
+
+ std::string::size_type lpos = basedir.size()-1;
+ for (int i=0; i<dirsback; ++i)
+ {
+ if ( lpos == 0 ) break;
+ std::string::size_type pos = basedir.rfind('/', lpos-1);
+//fprintf(stderr, "slash %d at offset %d (rfind from %d)\n", i, pos, lpos-1);
+ // no more slashes found, break and set at 1
+ if ( pos == std::string::npos ) lpos = 1;
+ else lpos = pos;
+ }
+ basedir.resize(lpos+1);
+
+//fprintf(stderr, "after chop basedir=%s\n", basedir.c_str());
+
+ // get dirname from basurl path
+ //_path = basedir + relative_url;
+ _path = basedir + in;
}
}
Index: gnash/libbase/URL.h
diff -u gnash/libbase/URL.h:1.2 gnash/libbase/URL.h:1.3
--- gnash/libbase/URL.h:1.2 Sat May 13 22:36:06 2006
+++ gnash/libbase/URL.h Sun May 14 22:47:01 2006
@@ -94,7 +94,16 @@
private:
- void init(const char* absurl);
+ void init_absolute(const char* absurl);
+
+ void init_relative(const std::string& relurl, const URL& baseurl);
+
+ /// Normalize a 'path' component of an url
+ //
+ /// Normalization currently only include removal
+ /// of adjacent slashes.
+ ///
+ static std::string normalize_path(const std::string& path);
std::string _proto;
Index: gnash/testsuite/libbase/Makefile.am
diff -u gnash/testsuite/libbase/Makefile.am:1.1
gnash/testsuite/libbase/Makefile.am:1.2
--- gnash/testsuite/libbase/Makefile.am:1.1 Sat May 13 22:34:14 2006
+++ gnash/testsuite/libbase/Makefile.am Sun May 14 22:47:01 2006
@@ -71,6 +71,7 @@
-I$(top_srcdir)/libgeometry \
$(MING_CFLAGS)
+abs_builddir=$(shell cd $(top_builddir)/testsuite/libbase; pwd)
noinst_PROGRAMS = \
CurlStreamTest \
@@ -80,4 +81,5 @@
CurlStreamTest_CPPFLAGS = '-DINPUT="$(srcdir)/CurlStreamTest.cpp"'
URLTest_SOURCES = URLTest.cpp
+URLTest_CPPFLAGS = '-DBUILDDIR="$(abs_builddir)"'
Index: gnash/testsuite/libbase/URLTest.cpp
diff -u gnash/testsuite/libbase/URLTest.cpp:1.1
gnash/testsuite/libbase/URLTest.cpp:1.2
--- gnash/testsuite/libbase/URLTest.cpp:1.1 Sat May 13 22:34:14 2006
+++ gnash/testsuite/libbase/URLTest.cpp Sun May 14 22:47:01 2006
@@ -123,13 +123,13 @@
runtest.fail ("proto-host filename str");
}
- /// Test https url (root path)
+ /// Test https url
URL u3("https://www.fake.it/path.swf");
if ( u3.protocol() == "https" ) {
runtest.pass ("https url proto");
} else {
runtest.fail ("https url proto");
- std::cerr << "obtained: " << u3.protocol();
+ std::cerr << "obtained: " << u3.protocol() << std::endl;
}
if ( u3.hostname() == "www.fake.it" ) {
runtest.pass ("https url hostname");
@@ -148,5 +148,97 @@
std::cerr << "Expected 'https://www.fake.it/path.swf', obtained
" << u3.str() << std::endl;
runtest.fail ("https url str");
}
+
+ /// Test http url with root path
+ URL u4("http://www.fake.it/");
+ if ( u4.protocol() == "http" ) {
+ runtest.pass ("http url root path 1 proto");
+ } else {
+ runtest.fail ("http url root path 1 proto");
+ std::cerr << "obtained: " << u4.protocol() << std::endl;
+ }
+ if ( u4.hostname() == "www.fake.it" ) {
+ runtest.pass ("http url root path 1 hostname");
+ } else {
+ runtest.fail ("http url root path 1 hostname");
+ }
+ if ( u4.path() == "/" ) {
+ runtest.pass ("http url root path 1 path");
+ } else {
+ std::cerr << "Expected '/', obtained " << u4.path() <<
std::endl;
+ runtest.fail ("http url root path 1 path");
+ }
+ if ( u4.str() == "http://www.fake.it/" ) {
+ runtest.pass ("http url root path 1 str");
+ } else {
+ std::cerr << "Expected 'http://www.fake.it/', obtained " <<
u4.str() << std::endl;
+ runtest.fail ("http url root path 1 str");
+ }
+
+ /// Test path-absolute proto-host-relative http url
+ URL u5("/index.html", u4);
+ if ( u5.protocol() == "http" ) {
+ runtest.pass ("path-abs proto-host-rel http url proto");
+ } else {
+ runtest.fail ("path-abs proto-host-rel http url proto");
+ std::cerr << "obtained: " << u5.protocol() << std::endl;
+ }
+ if ( u5.hostname() == "www.fake.it" ) {
+ runtest.pass ("path-abs proto-host-rel http url hostname");
+ } else {
+ runtest.fail ("path-abs proto-host-rel http url hostname");
+ }
+ if ( u5.path() == "/index.html" ) {
+ runtest.pass ("path-abs proto-host-rel http url path");
+ } else {
+ std::cerr << "Expected '/index.html', obtained " << u5.path()
<< std::endl;
+ runtest.fail ("path-abs proto-host-rel http url path");
+ }
+ if ( u5.str() == "http://www.fake.it/index.html" ) {
+ runtest.pass ("path-abs proto-host-rel http url str");
+ } else {
+ std::cerr << "Expected 'http://www.fake.it/index.html',
obtained " << u5.str() << std::endl;
+ runtest.fail ("path-abs proto-host-rel http url str");
+ }
+
+ /// Test back-seek path
+ URL u6("/usr/local/include/curl.h");
+ if ( u6.protocol() == "file" ) {
+ runtest.pass ("u6 proto");
+ } else {
+ runtest.fail ("u6 proto");
+ }
+ if ( u6.path() == "/usr/local/include/curl.h" ) {
+ runtest.pass ("u6 path");
+ } else {
+ runtest.fail ("u6 path");
+ }
+
+ URL u7("../../include/curl.h", u6);
+ if ( u7.protocol() == "file" ) {
+ runtest.pass ("u7 proto");
+ } else {
+ runtest.fail ("u7 proto");
+ }
+ if ( u7.path() == "/usr/include/curl.h" ) {
+ runtest.pass ("u7 path");
+ } else {
+ std::cerr << "Expected '/usr/include/curl.h', obtained " <<
u7.path() << std::endl;
+ runtest.fail ("u7 path");
+ }
+
+ URL u8("../..//../../../../tmp//curl.h", u6);
+ if ( u8.protocol() == "file" ) {
+ runtest.pass ("u8 proto");
+ } else {
+ runtest.fail ("u8 proto");
+ }
+ if ( u8.path() == "/tmp/curl.h" ) {
+ runtest.pass ("u8 path");
+ } else {
+ std::cerr << "Expected '/tmp/curl.h', obtained " << u8.path()
<< std::endl;
+ runtest.fail ("u8 path");
+ }
+
}
- [Gnash-commit] gnash ./ChangeLog libbase/URL.cpp libbase/URL.h...,
Sandro Santilli <=