Skip to content

Building a URI with query is awkward and dangerous #61

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

Closed
cmbrandenburg opened this issue Jul 7, 2015 · 1 comment
Closed

Building a URI with query is awkward and dangerous #61

cmbrandenburg opened this issue Jul 7, 2015 · 1 comment

Comments

@cmbrandenburg
Copy link
Contributor

The uri_builder class has two query methods, one that appends but incorrectly encodes and another that correctly encodes but replaces instead of appending.

First method

auto uri = network::uri_builder()
    .scheme("http")
    .host("example.com")
    .query("q1=foo bar")
    .query("q2=biz baz")
    .uri();
std::cout << uri << '\n';

What I expect: http://example.com?q1=foo%20bar&q2=biz%20baz
What I get: http://example.com?q2=biz%20baz

The actual output is correctly encoded, but the second query call replaced result of the first query call.

Second method

auto uri = network::uri_builder()
    .scheme("http")
    .host("example.com")
    .query("q1", "foo bar")
    .query("q2", "biz baz")
    .uri();
std::cout << uri << '\n';

What I expect: http://example.com?q1=foo%20bar&q2=biz%20baz
What I get: http://example.com?q1=foo bar&q2=biz baz

The actual output is incorrectly encoded, though at least the second query call appended to the result of the first query call.

Commentary

The inconsistency in the API is asking to be misused by Murphy. At the least, the two query methods should behave consistently with regards to each other.

Even better, both query methods should always percent-encode and always append. I struggle to think of a use case where I would want an incorrectly encoded URI, and I struggle to think of a use case where, when using uri_builder, I would want to undo a previous call to query by replacing its result with a subsequent call to query.

@glynos
Copy link
Member

glynos commented May 17, 2016

Addressed this in #82 by renaming the two overloads.

@glynos glynos closed this as completed May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants