From bf6ba105405a7eac70f1d36490d51962a4041ac0 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Thu, 20 Feb 2014 18:58:24 +0100 Subject: Reverting r13045. 1. It contains a memleak realpath allocates new memory if the second argument is NULL. In the added code, this memory is never freed. 2. Breaks build on Windows (realpath(...) not found) 3. Please don't add functions that use C-strings unnecessarily. Simply rewrite parseDataUri to parseDataUri(const std::string &uri), and use C++'s string methods. ("#include " is a huge red flag upon code review) 4. Please read this about "realpath" http://insanecoding.blogspot.ch/2007/11/pathmax-simply-isnt.html (bzr r13046) --- src/uri.cpp | 50 ++++---------------------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) (limited to 'src/uri.cpp') diff --git a/src/uri.cpp b/src/uri.cpp index a48aa8274..89f6f33e4 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -11,8 +11,6 @@ #include #include "uri.h" #include -#include -#include // XXX #include #include @@ -28,10 +26,6 @@ URI::URI(gchar const *preformed) throw(BadURIException) { if (!preformed) { throw MalformedURIException(); } - if( strncmp(preformed, "data:", 5)==0 ) { - parseDataUri( preformed + 5 ); - preformed = ""; // g_free? - } uri = xmlParseURI(preformed); if (!uri) { throw MalformedURIException(); @@ -141,38 +135,6 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException) filename = tmp.toNativeFilename(); return filename; } - -/* - * Parse data:... uris so we can access their data transparently. - * otherwise data: is considered a malformed protocol like http: - * and two // as appended and the data is stored in the path of the uri. - */ -bool URI::parseDataUri(const char *uri) { - - int len = (strchr(uri, ',') - uri) * sizeof(char); - - const char *data; - std::string head; - if (len > 0) { - head = std::string(uri, len); - data = uri + len; - } else { - head = "text/plain"; - data = uri; - } - - //bool base64 = false; - std::cout << "Header: " << head << "\n"; - std::cout << "Data: " << data << "\n"; - /*while(uri < data) { - if (strncmp(uri,"base64",6) == 0) - base64 = true; - if (strncmp(uri,"image/", - data = strchr(uri, ';'); - }*/ - return true; -} - /* * Returns the absolute path to an existing file referenced in this URI, * if the uri is data, the path is empty or the file doesn't exist, then @@ -187,16 +149,12 @@ const std::string URI::getFullPath(std::string const base) const { if(!base.empty() && !path.empty() && path[0] != '/') { path = Glib::build_filename(base, path); } - // Normalise path, this only works if all parts of the path exist - char *output = realpath(path.c_str(), NULL); - if(output == NULL) { - path.clear(); - } else // Re-check the existance of the file (make damn sure) - if(! g_file_test(output, G_FILE_TEST_EXISTS) - || g_file_test(output, G_FILE_TEST_IS_DIR) ) { + // Check the existance of the file + if(! g_file_test(path.c_str(), G_FILE_TEST_EXISTS) + || g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) ) { path.clear(); } - return std::string( output ); + return path; } -- cgit v1.2.3