Skip to content

Commit

Permalink
Merge topic 'productbuild-encode-pkg-url-ref'
Browse files Browse the repository at this point in the history
7954ba9 productbuild: escape pkg-ref urls
652210e cmSystemTools: Add EncodeURL helper

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2681
  • Loading branch information
bradking authored and kwrobot committed Dec 6, 2018
2 parents d69877f + 7954ba9 commit 81bea69
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Source/CPack/cmCPackPKGGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component,
xout.Content(this->GetPackageName(component));
} else {
xout.Content("file:./");
xout.Content(relativePackageLocation);
xout.Content(cmSystemTools::EncodeURL(relativePackageLocation,
/*escapeSlashes=*/false));
}
xout.EndElement(); // pkg-ref
}
Expand Down
21 changes: 1 addition & 20 deletions Source/CTest/cmCTestSubmitHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -407,26 +407,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
*this->LogFile << "\tUpload file: " << local_file << " to "
<< remote_file << std::endl;

std::string ofile;
for (char c : remote_file) {
char hexCh[4] = { 0, 0, 0, 0 };
hexCh[0] = c;
switch (c) {
case '+':
case '?':
case '/':
case '\\':
case '&':
case ' ':
case '=':
case '%':
sprintf(hexCh, "%%%02X", static_cast<int>(c));
ofile.append(hexCh);
break;
default:
ofile.append(hexCh);
}
}
std::string ofile = cmSystemTools::EncodeURL(remote_file);
std::string upload_as = url +
((url.find('?') == std::string::npos) ? '?' : '&') +
"FileName=" + ofile;
Expand Down
29 changes: 29 additions & 0 deletions Source/cmSystemTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,35 @@ bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
return (*endp == '\0') && (endp != str) && (errno == 0);
}

std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes)
{
std::string out;
for (char c : in) {
char hexCh[4] = { 0, 0, 0, 0 };
hexCh[0] = c;
switch (c) {
case '+':
case '?':
case '\\':
case '&':
case ' ':
case '=':
case '%':
sprintf(hexCh, "%%%02X", static_cast<int>(c));
break;
case '/':
if (escapeSlashes) {
strcpy(hexCh, "%2F");
}
break;
default:
break;
}
out.append(hexCh);
}
return out;
}

bool cmSystemTools::CreateSymlink(const std::string& origName,
const std::string& newName)
{
Expand Down
4 changes: 4 additions & 0 deletions Source/cmSystemTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ class cmSystemTools : public cmsys::SystemTools
static bool StringToLong(const char* str, long* value);
static bool StringToULong(const char* str, unsigned long* value);

/** Encode a string as a URL. */
static std::string EncodeURL(std::string const& in,
bool escapeSlashes = true);

#ifdef _WIN32
struct WindowsFileRetry
{
Expand Down

0 comments on commit 81bea69

Please sign in to comment.