Skip to content

Commit 5a9e6fe

Browse files
authored
[Sdk 632] Special character encoding exception fixed (#84)
* namespace added on countly classes * special character encoding issue fixed! * fixed import issue, added a new assert * auto -> char comment added * url encoding reverted to previous logic and fixed the issue. * change log added
1 parent dd64c61 commit 5a9e6fe

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* !! Major breaking change !! We are extracting the 'Event' class out of the 'Countly' class which will change how that class can be referenced. 'Countly::Event' will not work, you will have to use 'cly::Event' instead.
44
* !! Major breaking change !! Increased the compiler version required to compile the SDK. It's increased from version C++11 to C++14.
55
* Making network requests has been reworked. They will now be sent on a separate thread. Requests will also be added in an internal queue and will be sent one at a time.
6+
* Fixed a bug that caused an exception on windows when encoding data that contains special characters.
67

78
22.02.0
89
* Added 10-second time-outs for all windows HTTP transactions.

src/countly.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ std::chrono::system_clock::time_point Countly::getTimestamp() { return std::chro
702702
std::string Countly::encodeURL(const std::string &data) {
703703
std::ostringstream encoded;
704704

705-
for (auto character : data) {
705+
for (unsigned char character : data) {
706706
if (std::isalnum(character) || character == '.' || character == '_' || character == '~') {
707707
encoded << character;
708708
} else {
709-
encoded << '%' << std::setw(2) << std::hex << std::uppercase << (int)((unsigned char)character);
709+
encoded << '%' << std::setw(2) << std::hex << std::setfill('0') << std::uppercase << (unsigned int)((unsigned char)character);
710710
}
711711
}
712712

tests/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ HTTPCall popHTTPCall() {
119119

120120
TEST_CASE("urlencoding is correct") {
121121
CHECK(Countly::encodeURL("hello world") == "hello%20world");
122+
CHECK(Countly::encodeURL("hello.~world") == "hello.~world");
122123
CHECK(Countly::encodeURL("{\"key\":\"win\",\"count\":3}") == "%7B%22key%22%3A%22win%22%2C%22count%22%3A3%7D");
123-
// CHECK(Countly::encodeURL("测试") == "%E6%B5%8B%E8%AF%95"); // UTF-8 TODO: Needs to be fixed. This is throwing an exception.
124+
CHECK(Countly::encodeURL("测试") == "%E6%B5%8B%E8%AF%95");
124125
}
125126

126127
#ifdef COUNTLY_USE_CUSTOM_SHA256

0 commit comments

Comments
 (0)