From 08bbd3861567f571334fe3231f9e1d4678473401 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Wed, 3 Nov 2010 13:02:19 +0100 Subject: [PATCH] Bug - fixed is_local() in Uri --- src/Uri.cpp | 21 +++++++++++++++++---- src/Uri.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Uri.cpp b/src/Uri.cpp index 7b27dbf58..87c57d74a 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -33,6 +33,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// Uri::Uri () { + parsed = false; } //////////////////////////////////////////////////////////////////////////////// @@ -46,6 +47,7 @@ Uri::Uri (const Uri& other) user = other.user; port = other.port; protocol = other.protocol; + parsed = other.parsed; } } @@ -53,6 +55,7 @@ Uri::Uri (const Uri& other) Uri::Uri (const std::string& in, const std::string& configPrefix) { data = in; + parsed = false; if (configPrefix != "") expand(configPrefix); } @@ -73,6 +76,7 @@ Uri& Uri::operator= (const Uri& other) this->user = other.user; this->port = other.port; this->protocol = other.protocol; + this->parsed = other.parsed; } return *this; @@ -126,9 +130,9 @@ std::string Uri::extension () const //////////////////////////////////////////////////////////////////////////////// bool Uri::is_directory () const { - if (is_local ()) + if (is_local ()) { return Path (this->data).is_directory (); - else + } else return (path == ".") || (path == "") || (path[path.length()-1] == '/'); @@ -137,8 +141,11 @@ bool Uri::is_directory () const //////////////////////////////////////////////////////////////////////////////// bool Uri::is_local () const { - return ( (data.find("://") == std::string::npos) - && (data.find(":") == std::string::npos) ); + if (parsed) + return (protocol == ""); + else + return ( (data.find("://") == std::string::npos) + && (data.find(":") == std::string::npos) ); } //////////////////////////////////////////////////////////////////////////////// @@ -180,9 +187,13 @@ bool Uri::expand (const std::string& configPrefix ) //////////////////////////////////////////////////////////////////////////////// void Uri::parse () { + if (parsed) + return; + if (is_local ()) { path = data; + parsed = true; return; } @@ -233,6 +244,8 @@ void Uri::parse () port = host.substr (pos+1); host = host.substr (0,pos); } + + parsed = true; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Uri.h b/src/Uri.h index aa8357330..f81c92da9 100644 --- a/src/Uri.h +++ b/src/Uri.h @@ -62,6 +62,7 @@ public: std::string port; std::string user; std::string protocol; + bool parsed; }; #endif