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
@@ -582,4 +583,19 @@ namespace sio
582583 return ctx;
583584 }
584585#endif
586+
587+ std::string client_impl::encode_query_string (const std::string &query){
588+ ostringstream ss;
589+ ss << std::hex;
590+ // Percent-encode (RFC3986) non-alphanumeric characters.
591+ for (const char c : query){
592+ if ((c >= ' a' && c <= ' z' ) || (c>= ' A' && c<= ' Z' ) || (c >= ' 0' && c<= ' 9' )){
593+ ss << c;
594+ } else {
595+ ss << ' %' << std::uppercase << std::setw (2 ) << int ((unsigned char ) c) << std::nouppercase;
596+ }
597+ }
598+ ss << std::dec;
599+ return ss.str ();
600+ }
585601}
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