Skip to content

Commit

Permalink
Allow spaces (#100)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde authored Jun 17, 2024
1 parent 1839d58 commit dc0f791
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions resource_retriever/src/retriever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ size_t curlWriteFunc(void * buffer, size_t size, size_t nmemb, void * userp)
return size * nmemb;
}

static std::string escape_spaces(const std::string & url)
{
std::string new_mod_url;
new_mod_url.reserve(url.length());

std::string::size_type last_pos = 0;
std::string::size_type find_pos;

while (std::string::npos != (find_pos = url.find(" ", last_pos))) {
new_mod_url.append(url, last_pos, find_pos - last_pos);
new_mod_url += "%20";
last_pos = find_pos + std::string(" ").length();
}

// Take care for the rest after last occurrence
new_mod_url.append(url, last_pos, url.length() - last_pos);
return new_mod_url;
}

MemoryResource Retriever::get(const std::string & url)
{
std::string mod_url = url;
Expand All @@ -136,6 +155,9 @@ MemoryResource Retriever::get(const std::string & url)
mod_url = "file://" + package_path + mod_url;
}

// newer versions of curl do not accept spaces in URLs
mod_url = escape_spaces(mod_url);

curl_easy_setopt(curl_handle_, CURLOPT_URL, mod_url.c_str());
curl_easy_setopt(curl_handle_, CURLOPT_WRITEFUNCTION, curlWriteFunc);

Expand Down

0 comments on commit dc0f791

Please sign in to comment.