mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-12 17:19:05 -05:00
cmSystemTools: Add EncodeURL helper
Factor a URL encoding implementation out of CTest. Add an option to not escape slashes. Suggested-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
This commit is contained in:
@@ -407,26 +407,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
|
|||||||
*this->LogFile << "\tUpload file: " << local_file << " to "
|
*this->LogFile << "\tUpload file: " << local_file << " to "
|
||||||
<< remote_file << std::endl;
|
<< remote_file << std::endl;
|
||||||
|
|
||||||
std::string ofile;
|
std::string ofile = cmSystemTools::EncodeURL(remote_file);
|
||||||
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 upload_as = url +
|
std::string upload_as = url +
|
||||||
((url.find('?') == std::string::npos) ? '?' : '&') +
|
((url.find('?') == std::string::npos) ? '?' : '&') +
|
||||||
"FileName=" + ofile;
|
"FileName=" + ofile;
|
||||||
|
|||||||
@@ -3009,6 +3009,35 @@ bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
|
|||||||
return (*endp == '\0') && (endp != str) && (errno == 0);
|
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,
|
bool cmSystemTools::CreateSymlink(const std::string& origName,
|
||||||
const std::string& newName)
|
const std::string& newName)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -495,6 +495,10 @@ public:
|
|||||||
static bool StringToLong(const char* str, long* value);
|
static bool StringToLong(const char* str, long* value);
|
||||||
static bool StringToULong(const char* str, unsigned 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
|
#ifdef _WIN32
|
||||||
struct WindowsFileRetry
|
struct WindowsFileRetry
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user