Skip to content

Commit

Permalink
Merge pull request #138 from jianjunz/querystring
Browse files Browse the repository at this point in the history
URL encode query string.
  • Loading branch information
melode11 authored Oct 14, 2017
2 parents 08e83ea + ffff941 commit 6063cb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Binary file added src/internal/.DS_Store
Binary file not shown.
18 changes: 17 additions & 1 deletion src/internal/sio_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ namespace sio
query_str.append("&");
query_str.append(it->first);
query_str.append("=");
query_str.append(it->second);
string query_str_value=encode_query_string(it->second);
query_str.append(query_str_value);
}
m_query_string=move(query_str);

Expand Down Expand Up @@ -582,4 +583,19 @@ namespace sio
return ctx;
}
#endif

std::string client_impl::encode_query_string(const std::string &query){
ostringstream ss;
ss << std::hex;
// Percent-encode (RFC3986) non-alphanumeric characters.
for(const char c : query){
if((c >= 'a' && c <= 'z') || (c>= 'A' && c<= 'Z') || (c >= '0' && c<= '9')){
ss << c;
} else {
ss << '%' << std::uppercase << std::setw(2) << int((unsigned char) c) << std::nouppercase;
}
}
ss << std::dec;
return ss.str();
}
}
3 changes: 3 additions & 0 deletions src/internal/sio_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ namespace sio
context_ptr on_tls_init(connection_hdl con);
#endif

// Percent encode query string
std::string encode_query_string(const std::string &query);

// Connection pointer for client functions.
connection_hdl m_con;
client_type m_client;
Expand Down

0 comments on commit 6063cb1

Please sign in to comment.