summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2021-06-09 09:35:44 +0000
committerJulian Andres Klode <jak@debian.org>2021-06-09 09:35:44 +0000
commit416d468b84eb432ef1cbe7d3e80955bbdef035c7 (patch)
tree76d8caf99645fce37adc593ab4ae9c208b2d1945 /apt-pkg
parentaeae140b11220c8ca3692ef690bc51578f197992 (diff)
parenta2406cda4dd0aca523183ed6a8b651f06e0e63f9 (diff)
Merge branch 'fix/uriencodefilename' into 'main'
URI encode filename fields (again) See merge request apt-team/apt!175
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc12
-rw-r--r--apt-pkg/deb/debsrcrecords.cc30
-rw-r--r--apt-pkg/indexfile.cc5
3 files changed, 23 insertions, 24 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 225c4304a..d6ffaf34d 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -3853,16 +3853,16 @@ pkgAcqFile::pkgAcqFile(pkgAcquire *const Owner, string const &URI, HashStringLis
const string &DestDir, const string &DestFilename,
bool const IsIndexFile) : Item(Owner), d(NULL), IsIndexFile(IsIndexFile), ExpectedHashes(Hashes)
{
+ ::URI url{URI};
+ if (url.Path.find(' ') != std::string::npos || url.Path.find('%') == std::string::npos)
+ url.Path = pkgAcquire::URIEncode(url.Path);
+
if(!DestFilename.empty())
DestFile = DestFilename;
else if(!DestDir.empty())
- DestFile = DestDir + "/" + flNotDir(URI);
+ DestFile = DestDir + "/" + DeQuoteString(flNotDir(url.Path));
else
- DestFile = flNotDir(URI);
-
- ::URI url{URI};
- if (url.Path.find(' ') != std::string::npos || url.Path.find('%') == std::string::npos)
- url.Path = pkgAcquire::URIEncode(url.Path);
+ DestFile = DeQuoteString(flNotDir(url.Path));
// Create the item
Desc.URI = std::string(url);
diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc
index 89f3f1667..1fd0fdc12 100644
--- a/apt-pkg/deb/debsrcrecords.cc
+++ b/apt-pkg/deb/debsrcrecords.cc
@@ -23,6 +23,7 @@
#include <algorithm>
#include <string>
+#include <sstream>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
@@ -170,6 +171,7 @@ bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
+ auto const &posix = std::locale::classic();
for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
{
// derive field from checksum type
@@ -182,27 +184,23 @@ bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
string const Files = Sect.FindS(checksumField.c_str());
if (Files.empty() == true)
continue;
+ std::istringstream ss(Files);
+ ss.imbue(posix);
- // Iterate over the entire list grabbing each triplet
- const char *C = Files.c_str();
- while (*C != 0)
+ while (ss.good())
{
- string hash, size, path;
-
- // Parse each of the elements
- if (ParseQuoteWord(C, hash) == false ||
- ParseQuoteWord(C, size) == false ||
- ParseQuoteWord(C, path) == false)
- return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str());
-
+ std::string hash, path;
+ unsigned long long size;
if (iIndex == nullptr && checksumField == "Files")
{
- // the Files field has a different format than the rest in deb-changes files
std::string ignore;
- if (ParseQuoteWord(C, ignore) == false ||
- ParseQuoteWord(C, path) == false)
- return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str());
+ ss >> hash >> size >> ignore >> ignore >> path;
}
+ else
+ ss >> hash >> size >> path;
+
+ if (ss.fail() || hash.empty() || path.empty())
+ return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str());
HashString const hashString(*type, hash);
if (Base.empty() == false)
@@ -226,7 +224,7 @@ bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
// we haven't seen this file yet
pkgSrcRecords::File F;
F.Path = path;
- F.FileSize = strtoull(size.c_str(), NULL, 10);
+ F.FileSize = size;
F.Hashes.push_back(hashString);
F.Hashes.FileSize(F.FileSize);
diff --git a/apt-pkg/indexfile.cc b/apt-pkg/indexfile.cc
index ef3486ab8..f13b52940 100644
--- a/apt-pkg/indexfile.cc
+++ b/apt-pkg/indexfile.cc
@@ -9,6 +9,7 @@
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/acquire.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/deblistparser.h>
@@ -174,7 +175,7 @@ pkgDebianIndexTargetFile::pkgDebianIndexTargetFile(IndexTarget const &Target, bo
/*}}}*/
std::string pkgDebianIndexTargetFile::ArchiveURI(std::string const &File) const/*{{{*/
{
- return Target.Option(IndexTarget::REPO_URI) + File;
+ return Target.Option(IndexTarget::REPO_URI) + pkgAcquire::URIEncode(File);
}
/*}}}*/
std::string pkgDebianIndexTargetFile::Describe(bool const Short) const /*{{{*/
@@ -281,7 +282,7 @@ std::string pkgDebianIndexRealFile::Describe(bool const /*Short*/) const/*{{{*/
/*}}}*/
std::string pkgDebianIndexRealFile::ArchiveURI(std::string const &/*File*/) const/*{{{*/
{
- return "file:" + File;
+ return "file:" + pkgAcquire::URIEncode(File);
}
/*}}}*/
std::string pkgDebianIndexRealFile::IndexFileName() const /*{{{*/