Skip to content

Commit

Permalink
Merge pull request #9 from adam-p/master
Browse files Browse the repository at this point in the history
Fix URL::Encode crash on Windows
  • Loading branch information
adam-p authored Sep 1, 2020
2 parents 5d003b4 + 0da7669 commit 22fef8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ string URL::Encode(const string& s, bool full) {
string::value_type c = (*i);

// Keep alphanumeric and other accepted characters intact
if (!full && (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')) {
if (!full && (isalnum((unsigned char)c) || c == '-' || c == '_' || c == '.' || c == '~')) {
escaped << c;
continue;
}
Expand Down
6 changes: 6 additions & 0 deletions url_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ TEST(TestURL, EncodeNotFull)

enc = URL::Encode("{\"k1\": \"v\", \"k2\": 123}", false);
ASSERT_EQ(enc, "%7B%22k1%22%3A%20%22v%22%2C%20%22k2%22%3A%20123%7D");

enc = URL::Encode("", false);
ASSERT_EQ(enc, "%E2%8C%98");
}

TEST(TestURL, EncodeFull)
Expand All @@ -124,4 +127,7 @@ TEST(TestURL, EncodeFull)

enc = URL::Encode("{\"k1\": \"v\", \"k2\": 123}", true);
ASSERT_EQ(enc, "%7B%22%6B%31%22%3A%20%22%76%22%2C%20%22%6B%32%22%3A%20%31%32%33%7D");

enc = URL::Encode("", false);
ASSERT_EQ(enc, "%E2%8C%98");
}

0 comments on commit 22fef8d

Please sign in to comment.