Skip to content

URL encode query string. #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -585,4 +586,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