Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRemove trailing question mark on empty query #494
Conversation
|
There’s a question whether there are current users of the However, looking at the diff, including |
|
I had assumed the current behavior was consistent with avoiding all non-specified normalizations. To add this normalization I'm using something like this, also usable as a workaround: let mut remove_query = false;
if let Some(q) = url.query() {
if q.is_empty() {
remove_query = true;
}
}
if remove_query {
url.set_query(None);
}FWIW: I think dropping an empty query is form of normalization, albeit a commonly desired and less controversial one. Edit: NLL (2018 edition) can make above much simpler: if let Some(q) = url.query() {
if q.is_empty() {
url.set_query(None);
}
} |
|
Adding the '?' to the serialization is really wrong, with those points in mind. The reason behind this modification was avoiding having to remove the query after every empty serialization, maybe that's not a relevant concern, since the query removal is not that expensive. My first idea was doing this empty checking on reqwest side, but maybe this modification would be useful here also. I can remake this branch to use @dekellum version which looks cleaner and already pass tests without changes if this change is desired, but I feel that this desirability is undecided. |
aaneto commentedApr 18, 2019
•
edited by larsbergstrom
Hello everyone!
I have been tinkering with the implementation of query_pairs_mut after looking at this issue on the reqwest project. The core of the issue is that a serialization of an empty query insert a '?' at the end of the url.
I went on to try and make the serialization of query_pairs_mut to only insert a trailing question mark after the first serialization. Making
url.query_pairs_mut().clear();equivalent tourl.set_query(None).I don't know if this behaviour is desired on the rust-url side, but would like to know if this change is feasible.
This change is