Skip to content

Commit

Permalink
Auto merge of #2737 - aidanhs:aphs-hash-url-serialization, r=alexcric…
Browse files Browse the repository at this point in the history
…hton

Hash url serialization to ensure hash stability

`as_str` is documented to return the serialization of a url (http://servo.github.io/rust-url/url/struct.Url.html#method.as_str).
The serialization of a url has a spec (https://url.spec.whatwg.org/#url-serializing).

Hashing the serialization of a url insulates cargo against possible decisions to alter how rust-url does hashing (I've observed it happening twice). Note that rust-url happens to do this internally (but is not guaranteed to in future) and so this change doesn't actually have any effect on hash values.

r? @alexcrichton

Closes #1710
  • Loading branch information
bors committed May 24, 2016
2 parents ca743f3 + b691f1e commit 1ed0727
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cargo/core/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,17 @@ impl Ord for SourceIdInner {
}
}

// The hash of SourceId is used in the name of some Cargo folders, so shouldn't
// vary. `as_str` gives the serialisation of a url (which has a spec) and so
// insulates against possible changes in how the url crate does hashing.
impl hash::Hash for SourceId {
fn hash<S: hash::Hasher>(&self, into: &mut S) {
self.inner.kind.hash(into);
match *self.inner {
SourceIdInner { kind: Kind::Git(..), ref canonical_url, .. } => {
canonical_url.hash(into)
canonical_url.as_str().hash(into)
}
_ => self.inner.url.hash(into),
_ => self.inner.url.as_str().hash(into),
}
}
}
Expand Down

0 comments on commit 1ed0727

Please sign in to comment.