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

feat(entitytag): Add EntityTag comparison, make EntityTag safe to use #409

Merged
merged 1 commit into from
Mar 30, 2015
Merged

Conversation

pyfisch
Copy link
Contributor

@pyfisch pyfisch commented Mar 30, 2015

Adds strong and weak comparison to EntityTag as described in the RFC, add tests for this. Make EntityTag safe to use by hiding the tag field, this prevents users from inserting malicious values for the tag. Invalid values can screw up header formatting and may allow to insert headers. Introduce EntityTag::new(), .tag() and .set_tag() methods. Fix Display trait for EntityTag. DQUOTES were missing. Remove custom formatting in ETag header. Improve docs.

BREAKING_CHANGE: EntityTag.tag is private, use EntityTag.tag() and EntityTag.set_tag("foobar") to access.

@GitCop
Copy link

GitCop commented Mar 30, 2015

Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:

  • Commit: 85dac24
    • Your commit message body contains a line that is longer than 100 characters

Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

/// Set the tag.
/// # Panics
/// If the tag contains invalid characters.
pub fn set_tag(&mut self, tagslice: &str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd to me for a setter to ask for a reference. I'd expect either a String, or Into<String>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will use Into<String>. It looks like Into<String> won't work yet, so I use String.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's OK. Switching to Into<String> should be a non-breaking change.

@seanmonstar
Copy link
Member

@pyfisch This is superb! Just one minor comment.

/// Constructs a new EntityTag.
/// # Panics
/// If the tag contains invalid characters.
pub fn new(weak: bool, tagslice: &str) -> EntityTag {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the same here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes.

Specifically, the only way to pass a &str is to have a static str, or they need to create a String. Since they have already allocated a String in order pass a reference, it's wasteful to allocate a new String, especially since they likely just threw away the original they made.

Adds strong and weak comparison to EntityTag as described in the RFC,
add tests for this. Make EntityTag safe to use by hiding the tag field,
this prevents users from inserting malicious values for the tag. Invalid
values can screw up header formatting and may allow to insert headers.
Introduce EntityTag::new(), .tag() and .set_tag() methods. Fix Display
trait for EntityTag. DQUOTES were missing. Remove custom formatting in ETag
header. Improve docs.

BREAKING_CHANGE: EntityTag.tag is private, use EntityTag.tag() and
EntityTag.set_tag("foobar") to access it.
@pyfisch
Copy link
Contributor Author

pyfisch commented Mar 30, 2015

Updated code.

seanmonstar added a commit that referenced this pull request Mar 30, 2015
feat(entitytag): Add EntityTag comparison, make EntityTag safe to use
@seanmonstar seanmonstar merged commit 6775e99 into hyperium:master Mar 30, 2015
@pyfisch pyfisch deleted the entitytag branch March 30, 2015 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants