From 057e8a4cfad296f592871cf4ab675ea9fe920826 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 26 Dec 2004 16:42:30 +0000 Subject: [PATCH] Fixed bug in URL parsing. --- src/messaging/url.cpp | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/messaging/url.cpp b/src/messaging/url.cpp index f8b24fd7..b770482b 100644 --- a/src/messaging/url.cpp +++ b/src/messaging/url.cpp @@ -143,26 +143,34 @@ void url::parse(const string& str) string username; string password; - if (atPos != string::npos && atPos < slashPos) + if (proto == PROTOCOL_FILE) { - const string userPart(str.begin() + protoEnd, str.begin() + atPos); - const string::size_type colonPos = userPart.find(':'); - - if (colonPos == string::npos) - { - username = userPart; - } - else - { - username = string(userPart.begin(), userPart.begin() + colonPos); - password = string(userPart.begin() + colonPos + 1, userPart.end()); - } - - hostPart = string(str.begin() + atPos + 1, str.begin() + slashPos); + // No user name, password and host part. + slashPos = protoEnd + 3; } else { - hostPart = string(str.begin() + protoEnd, str.begin() + slashPos); + if (atPos != string::npos && atPos < slashPos) + { + const string userPart(str.begin() + protoEnd + 3, str.begin() + atPos); + const string::size_type colonPos = userPart.find(':'); + + if (colonPos == string::npos) + { + username = userPart; + } + else + { + username = string(userPart.begin(), userPart.begin() + colonPos); + password = string(userPart.begin() + colonPos + 1, userPart.end()); + } + + hostPart = string(str.begin() + atPos + 1, str.begin() + slashPos); + } + else + { + hostPart = string(str.begin() + protoEnd + 3, str.begin() + slashPos); + } } // Host/port @@ -182,7 +190,7 @@ void url::parse(const string& str) } // Path - string path(str.begin() + slashPos, str.end()); + string path = stringUtils::trim(string(str.begin() + slashPos, str.end())); if (path == "/") path.clear();