mirror of
https://github.com/aria2/aria2.git
synced 2025-01-08 11:01:38 +00:00
util::percentEncodeMini: Fix regression bug removed unsignedness
srange-based for around std::string is convenient but several functions depend unsigned char for correctness and readability.
This commit is contained in:
parent
9768aa9fad
commit
b772aa6a5e
10
src/util.cc
10
src/util.cc
@ -458,9 +458,9 @@ std::string percentEncodeMini(const std::string& src)
|
||||
return src;
|
||||
}
|
||||
std::string result;
|
||||
for (const auto& c: src) {
|
||||
for (auto c: src) {
|
||||
if(!inPercentEncodeMini(c)) {
|
||||
result += fmt("%%%02X", c);
|
||||
result += fmt("%%%02X", static_cast<unsigned char>(c));
|
||||
} else {
|
||||
result += c;
|
||||
}
|
||||
@ -1725,7 +1725,8 @@ bool detectDirTraversal(const std::string& s)
|
||||
if(s.empty()) {
|
||||
return false;
|
||||
}
|
||||
for (const auto& ch: s) {
|
||||
for (auto c : s) {
|
||||
unsigned char ch = c;
|
||||
if (in(ch, 0x00u, 0x1fu) || ch == 0x7fu) {
|
||||
return true;
|
||||
}
|
||||
@ -1748,7 +1749,8 @@ std::string escapePath(const std::string& s)
|
||||
{ '"', '*', ':', '<', '>', '?', '\\', '|' };
|
||||
#endif // __MINGW32__
|
||||
std::string d;
|
||||
for(const auto& c: s) {
|
||||
for(auto cc: s) {
|
||||
unsigned char c = cc;
|
||||
if(in(c, 0x00u, 0x1fu) || c == 0x7fu
|
||||
#ifdef __MINGW32__
|
||||
|| std::find(std::begin(WIN_INVALID_PATH_CHARS),
|
||||
|
@ -64,6 +64,7 @@ class UtilTest:public CppUnit::TestFixture {
|
||||
CPPUNIT_TEST(testUitos);
|
||||
CPPUNIT_TEST(testNtoh64);
|
||||
CPPUNIT_TEST(testPercentEncode);
|
||||
CPPUNIT_TEST(testPercentEncodeMini);
|
||||
CPPUNIT_TEST(testHtmlEscape);
|
||||
CPPUNIT_TEST(testJoinPath);
|
||||
CPPUNIT_TEST(testParseIndexPath);
|
||||
@ -132,6 +133,7 @@ public:
|
||||
void testUitos();
|
||||
void testNtoh64();
|
||||
void testPercentEncode();
|
||||
void testPercentEncodeMini();
|
||||
void testHtmlEscape();
|
||||
void testJoinPath();
|
||||
void testParseIndexPath();
|
||||
@ -1879,6 +1881,12 @@ void UtilTest::testPercentEncode()
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1%5EA%20"), util::percentEncode("1^A "));
|
||||
}
|
||||
|
||||
void UtilTest::testPercentEncodeMini()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("%80"),
|
||||
util::percentEncodeMini({(char)0x80}));
|
||||
}
|
||||
|
||||
void UtilTest::testHtmlEscape()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2<>"'util"),
|
||||
|
Loading…
Reference in New Issue
Block a user