aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/utility/url.cpp17
-rw-r--r--src/utility/urlUtils.cpp37
2 files changed, 45 insertions, 9 deletions
diff --git a/src/utility/url.cpp b/src/utility/url.cpp
index 0c0a5799..919a3610 100644
--- a/src/utility/url.cpp
+++ b/src/utility/url.cpp
@@ -181,12 +181,12 @@ void url::parse(const string& str)
if (colonPos == string::npos)
{
- host = hostPart;
+ host = utility::stringUtils::trim(hostPart);
}
else
{
- host = string(hostPart.begin(), hostPart.begin() + colonPos);
- port = string(hostPart.begin() + colonPos + 1, hostPart.end());
+ host = utility::stringUtils::trim(string(hostPart.begin(), hostPart.begin() + colonPos));
+ port = utility::stringUtils::trim(string(hostPart.begin() + colonPos + 1, hostPart.end()));
}
// Path
@@ -198,8 +198,12 @@ void url::parse(const string& str)
// Some sanity check
if (proto.empty())
throw exceptions::malformed_url("No protocol specified");
- else if (host.empty() && path.empty()) // Accept empty host (eg. "file:///home/vincent/mydoc")
- throw exceptions::malformed_url("No host specified");
+ else if (host.empty())
+ {
+ // Accept empty host (eg. "file:///home/vincent/mydoc")
+ if (proto != PROTOCOL_FILE)
+ throw exceptions::malformed_url("No host specified");
+ }
bool onlyDigit = true;
@@ -217,6 +221,9 @@ void url::parse(const string& str)
iss >> portNum;
+ if (portNum == 0)
+ portNum = UNSPECIFIED_PORT;
+
// Now, save URL parts
m_protocol = proto;
diff --git a/src/utility/urlUtils.cpp b/src/utility/urlUtils.cpp
index 6099c19b..70a988cf 100644
--- a/src/utility/urlUtils.cpp
+++ b/src/utility/urlUtils.cpp
@@ -34,17 +34,18 @@ const string urlUtils::encode(const string& s)
{
const char_t c = *it;
- if (parserHelpers::isPrint(c) && c != '%')
+ if (parserHelpers::isPrint(c) && !parserHelpers::isSpace(c) && c != '%')
{
result += c;
}
else
{
char hex[4];
+ const unsigned char k = static_cast <unsigned char>(c);
hex[0] = '%';
- hex[1] = c / 16;
- hex[2] = c % 16;
+ hex[1] = "0123456789ABCDEF"[k / 16];
+ hex[2] = "0123456789ABCDEF"[k % 16];
hex[3] = 0;
result += hex;
@@ -71,7 +72,35 @@ const string urlUtils::decode(const string& s)
const char_t p = (++it != s.end() ? *it : 0);
const char_t q = (++it != s.end() ? *it : 0);
- result += static_cast <string::value_type>(p * 16 + q);
+ unsigned char r = 0;
+
+ switch (p)
+ {
+ case 0: r = '?'; break;
+ case 'a': case 'A': r = 10; break;
+ case 'b': case 'B': r = 11; break;
+ case 'c': case 'C': r = 12; break;
+ case 'd': case 'D': r = 13; break;
+ case 'e': case 'E': r = 14; break;
+ case 'f': case 'F': r = 15; break;
+ default: r = p - '0'; break;
+ }
+
+ r *= 16;
+
+ switch (q)
+ {
+ case 0: r = '?'; break;
+ case 'a': case 'A': r += 10; break;
+ case 'b': case 'B': r += 11; break;
+ case 'c': case 'C': r += 12; break;
+ case 'd': case 'D': r += 13; break;
+ case 'e': case 'E': r += 14; break;
+ case 'f': case 'F': r += 15; break;
+ default: r += q - '0'; break;
+ }
+
+ result += static_cast <string::value_type>(r);
if (it != s.end())
++it;