File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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;
You can’t perform that action at this time.
0 commit comments