Repository navigation
Conversation
… and PartialOrd
PathAndQuery::as_str(), PartialEq<str>, and PartialOrd already normalize
an empty internal buffer to "/", while PartialEq<PathAndQuery> and Hash
compared and hashed self.data directly.
As a result, an empty PathAndQuery (such as from
Uri::builder().path_and_query("") or fragment-only inputs like "#frag")
compared PartialOrd::Equal to PathAndQuery::from_static("/") yet returned
false for == and produced a different Hash, violating the
PartialOrd/PartialEq and Eq/Hash contracts.
Use self.as_str() in both PartialEq and Hash implementations and add
regression tests covering empty, fragment-only, and builder-constructed
values.
Signed-off-by: Yan Chen <yan8925298@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PathAndQuery::as_str(),PartialEq<str>,Display, andPartialOrdall normalize an empty internal buffer (self.data == "") to"/". However,PartialEq<PathAndQuery>andHashpreviously compared and hashedself.datadirectly.Because an empty
PathAndQuerycan be constructed viaUri::builder().path_and_query("")or fragment-only inputs like"#frag", comparing it withPathAndQuery::from_static("/")violated thePartialOrd/PartialEqandEq/Hashcontracts:a.as_str() == b.as_str()("/")a.partial_cmp(&b) == Some(Ordering::Equal)a == breturnedfalseandhash(a) != hash(b).Changes
PartialEq for PathAndQueryandHash for PathAndQueryinsrc/uri/path.rsto useself.as_str(), matchingPartialEq<str>andPartialOrd.empty_and_slash_eq_hash_ord_consistentcoveringPathAndQuery::empty(), fragment-only parsing ("#frag"), andUri::builder().path_and_query("")vsUri::from_static("http://example.com/").Verification
assertion left == right failed: left: /, right: /) and passes after.cargo test(150 unit tests, integration tests, and 229 doctests) andcargo fmt -- --checkpass.