summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/strutl.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-08-01 21:45:29 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2016-08-10 23:20:15 +0200
commita1f3ac8aba0675321dd46d074af8abcbb10c19fd (patch)
tree68ae5a4acf24b3b38b2464acb18cc46ebda95e40 /apt-pkg/contrib/strutl.cc
parentb9e6db821a6ddbc5bf6a90c80c296d4e91283a63 (diff)
allow user@host (aka: no password) in URI parsing
If the URI had no password the username was ignored
Diffstat (limited to 'apt-pkg/contrib/strutl.cc')
-rw-r--r--apt-pkg/contrib/strutl.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 7b6bb2854..6c72859d4 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1639,13 +1639,15 @@ void URI::CopyFrom(const string &U)
I = FirstColon + 1;
if (I > SingleSlash)
I = SingleSlash;
- for (; I < SingleSlash && *I != ':'; ++I);
- string::const_iterator SecondColon = I;
-
- // Search for the @ after the colon
- for (; I < SingleSlash && *I != '@'; ++I);
- string::const_iterator At = I;
-
+
+ // Search for the @ separating user:pass from host
+ auto const RevAt = std::find(
+ std::string::const_reverse_iterator(SingleSlash),
+ std::string::const_reverse_iterator(I), '@');
+ string::const_iterator const At = RevAt.base() == I ? SingleSlash : std::prev(RevAt.base());
+ // and then look for the colon between user and pass
+ string::const_iterator const SecondColon = std::find(I, At, ':');
+
// Now write the host and user/pass
if (At == SingleSlash)
{