Skip to content

Commit

Permalink
fix: new urlencoding failed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Oct 5, 2023
1 parent aa34d14 commit 9fa7cb2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/dpp/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,19 +555,22 @@ std::string url_encode(const std::string &value) {
// Reserve worst-case encoded length of string, input length * 3
std::string escaped(value.length() * 3, '\0');
char* data = escaped.data();
int len = 0;
for (auto i = value.begin(); i != value.end(); ++i) {
unsigned char c = (unsigned char)(*i);
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
// Keep alphanumeric and other accepted characters intact
*data++ = c;
len++;
} else {
// Any other characters are percent-encoded
*data++ = '%';
*data++ = hex[c >> 4];
*data++ = hex[c & 0x0f];
len += 3;
}
}
*data = 0;
escaped.resize(len);
return escaped;
}

Expand Down

0 comments on commit 9fa7cb2

Please sign in to comment.