summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/strutl.cc16
-rw-r--r--doc/apt-key.8.xml2
-rw-r--r--test/libapt/uri_test.cc12
3 files changed, 22 insertions, 8 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)
{
diff --git a/doc/apt-key.8.xml b/doc/apt-key.8.xml
index 093abfe8a..57200b1ed 100644
--- a/doc/apt-key.8.xml
+++ b/doc/apt-key.8.xml
@@ -39,7 +39,7 @@
<para>
Note that if usage of <command>apt-key</command> is desired the additional
installation of the GNU Privacy Guard suite (packaged in
- <package>gnupg</package>) is required. For this reason alone the programatic
+ <package>gnupg</package>) is required. For this reason alone the programmatic
usage (especially in package maintainerscripts!) is strongly discouraged.
Further more the output format of all commands is undefined and can and does
change whenever the underlying commands change. <command>apt-key</command> will
diff --git a/test/libapt/uri_test.cc b/test/libapt/uri_test.cc
index d8f3ffe45..8296ca6a0 100644
--- a/test/libapt/uri_test.cc
+++ b/test/libapt/uri_test.cc
@@ -28,6 +28,18 @@ TEST(URITest, BasicHTTP)
EXPECT_EQ("http://ualberta.ca", URI::SiteOnly(U));
EXPECT_EQ("http://ualberta.ca/blah", URI::ArchiveOnly(U));
EXPECT_EQ("http://ualberta.ca/blah", URI::NoUserPassword(U));
+ // just a user
+ U = URI("https://apt@example.org/blah");
+ EXPECT_EQ("https", U.Access);
+ EXPECT_EQ("apt", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("example.org", U.Host);
+ EXPECT_EQ("/blah", U.Path);
+ EXPECT_EQ("https://apt@example.org/blah", (std::string)U);
+ EXPECT_EQ("https://example.org", URI::SiteOnly(U));
+ EXPECT_EQ("https://example.org/blah", URI::ArchiveOnly(U));
+ EXPECT_EQ("https://example.org/blah", URI::NoUserPassword(U));
}
TEST(URITest, SingeSlashFile)
{