Skip to content
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

Provide functions to put literal {";","&","="} into query strings #43

Open
dsheets opened this issue Apr 28, 2014 · 4 comments
Open

Provide functions to put literal {";","&","="} into query strings #43

dsheets opened this issue Apr 28, 2014 · 4 comments
Milestone

Comments

@dsheets
Copy link
Member

dsheets commented Apr 28, 2014

No description provided.

@dsheets
Copy link
Member Author

dsheets commented Apr 28, 2014

See 1ef3f1d which proposes also to escape !, $, and ,. Are these query string conventions scheme-specific?

@edwintorok
Copy link

Apparently some applications don't like having the ; encoded, for example running the URL below through Uri.of_string and Uri.to_string changes its semantics:

utop # Uri.to_string (Uri.of_string "http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README");;
- : bytes = "http://repo.or.cz/w/alt-git.git?a=blob_plain%3Bf=gitweb/README" 

The URL with %3B gives 400 - Invalid action parameter, but replacing ; with & or keeping it as ';' works:

utop # Uri.to_string (Uri.of_string "http://repo.or.cz/w/alt-git.git?a=blob_plain&f=gitweb/README");;
- : bytes = "http://repo.or.cz/w/alt-git.git?a=blob_plain&f=gitweb/README"

Perhaps Uri.to_string should have a parameter to try to keep the Uri as close as possible to its original form (if it still knows what that was).

@dsheets
Copy link
Member Author

dsheets commented May 28, 2015

This is a longstanding issue which is quite simple to fix but requires breaking interface compatibility (similar to most of the other awaited changes).

Unfortunately, there is no way to retain full control over this behavior at the present time. A solution that may work for you is to use the new verbatim_query function to extract the query string as written, use Stringext.split ~on:';', use String.concat to replace ';' with '&', and then use with_query to set the query string. I realize this dance is far from ideal and I'll push some designs for the 2.0 interface which addresses this and related (#18,#43,#65) issues as soon as I can find a solid block of time.

@edwintorok
Copy link

Thanks, something like this worked:

match Uri.verbatim_query uri with
  | Some q ->
    Uri.with_query uri (Uri.query_of_encoded (Stringext.replace_all q ~pattern:";" ~with_:"&"))
  | None -> uri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants