Skip to content

Commit ffff941

Browse files
committed
URL encode query string.
Percent encode query string so it can handle non-ascii characters and reserved characters.
1 parent 725a8e0 commit ffff941

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/internal/.DS_Store

6 KB
Binary file not shown.

src/internal/sio_client_impl.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ namespace sio
9595
query_str.append("&");
9696
query_str.append(it->first);
9797
query_str.append("=");
98-
query_str.append(it->second);
98+
string query_str_value=encode_query_string(it->second);
99+
query_str.append(query_str_value);
99100
}
100101
m_query_string=move(query_str);
101102

@@ -585,4 +586,19 @@ namespace sio
585586
return ctx;
586587
}
587588
#endif
589+
590+
std::string client_impl::encode_query_string(const std::string &query){
591+
ostringstream ss;
592+
ss << std::hex;
593+
// Percent-encode (RFC3986) non-alphanumeric characters.
594+
for(const char c : query){
595+
if((c >= 'a' && c <= 'z') || (c>= 'A' && c<= 'Z') || (c >= '0' && c<= '9')){
596+
ss << c;
597+
} else {
598+
ss << '%' << std::uppercase << std::setw(2) << int((unsigned char) c) << std::nouppercase;
599+
}
600+
}
601+
ss << std::dec;
602+
return ss.str();
603+
}
588604
}

src/internal/sio_client_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ namespace sio
176176
context_ptr on_tls_init(connection_hdl con);
177177
#endif
178178

179+
// Percent encode query string
180+
std::string encode_query_string(const std::string &query);
181+
179182
// Connection pointer for client functions.
180183
connection_hdl m_con;
181184
client_type m_client;

0 commit comments

Comments
 (0)