Skip to content

Fix a lifetime bug uncovered by NLL, thanks @lqd #457

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
Aug 23, 2018
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name = "url"
# When updating version, also modify html_root_url in the lib.rs
version = "1.6.0"
version = "1.6.1"
authors = ["The rust-url developers"]

description = "URL library for Rust, based on the WHATWG URL Standard"
Expand Down
12 changes: 10 additions & 2 deletions src/form_urlencoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,16 @@ impl<'a> Target for &'a mut String {
// * `Serializer` keeps its target in a private field
// * Unlike in other `Target` impls, `UrlQuery::finished` does not return `Self`.
impl<'a> Target for ::UrlQuery<'a> {
fn as_mut_string(&mut self) -> &mut String { &mut self.url.serialization }
fn finish(self) -> &'a mut ::Url { self.url }
fn as_mut_string(&mut self) -> &mut String {
&mut self.url.as_mut().unwrap().serialization
}

fn finish(mut self) -> &'a mut ::Url {
let url = self.url.take().unwrap();
url.restore_already_parsed_fragment(self.fragment.take());
url
}

type Finished = &'a mut ::Url;
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ impl Url {
self.serialization.push('?');
}

let query = UrlQuery { url: self, fragment: fragment };
let query = UrlQuery { url: Some(self), fragment: fragment };
form_urlencoded::Serializer::for_suffix(query, query_start + "?".len())
}

Expand Down Expand Up @@ -2373,13 +2373,15 @@ fn io_error<T>(reason: &str) -> io::Result<T> {
/// Implementation detail of `Url::query_pairs_mut`. Typically not used directly.
#[derive(Debug)]
pub struct UrlQuery<'a> {
url: &'a mut Url,
url: Option<&'a mut Url>,
fragment: Option<String>,
}

impl<'a> Drop for UrlQuery<'a> {
fn drop(&mut self) {
self.url.restore_already_parsed_fragment(self.fragment.take())
if let Some(url) = self.url.take() {
url.restore_already_parsed_fragment(self.fragment.take())
}
}
}

Expand Down