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

Strip angle brackets from author email before passing to template. #6243

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

btashton
Copy link
Contributor

Some people already have angle brackets around their email in
git settings or other author sources. Right now if you create
a new project the Cargo.toml would render something like:

authors = ["bar <<foo@baz>>"]

instead of

authors = ["bar <foo@baz>"]

This detects the emails that start and end with <> and removes them.

@btashton
Copy link
Contributor Author

I'm only a few days into learning Rust, so please let me know if I am doing something totally off-base here.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@@ -660,7 +660,15 @@ fn discover_author() -> CargoResult<(String, Option<String>)> {
.or_else(|| get_environment_variable(&email_variables[3..]));

let name = name.trim().to_string();
let email = email.map(|s| s.trim().to_string());
let email = email.map(|mut s| {
s = s.trim().to_string();
Copy link
Member

Choose a reason for hiding this comment

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

This might be best done with a bit more slicing, like:

let mut s = s.trim();
if s.starts_with("<") && s.ends_with(">") {
    s = &s[1..s.len() - 1];
}
s.to_string()

Copy link
Member

Choose a reason for hiding this comment

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

Also, could a comment be added why it's being trimmed?

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'll fix it up with the slicing. But I actually do not know why there is a trim in there, it is from the original code. My guess is that some sources might include a newline and we want to make sure that is gone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexcrichton PR has been updated with this change minus the comment.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah the trim() is sort of just for good measure, I'm not sure if it's solidly motivated one way or the other.

As a mild stylistic note as well, the { after the if clause typically comes on the same line instead of the next line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Falling into my C habit. Fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Ok thinks! And for a comment FWIW I was just thinking of your use case of stripping the angle brackets. Would you be ok adding that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@btashton btashton force-pushed the strip_email_bracket branch 2 times, most recently from 1a1705a to 5c7e8eb Compare November 1, 2018 21:32
Some people already have angle brackets around their email in
git settings or other author sources. Right now if you create
a new project the Cargo.toml would render something like:

authors = ["bar <<foo@baz>>"]

instead of

authors = ["bar <foo@baz>"]

This detects the emails that start and end with <> and removes them.
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Nov 1, 2018

📌 Commit 7d57948 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Nov 1, 2018

⌛ Testing commit 7d57948 with merge bd32ba7...

bors added a commit that referenced this pull request Nov 1, 2018
Strip angle brackets from author email before passing to template.

Some people already have angle brackets around their email in
git settings or other author sources. Right now if you create
a new project the Cargo.toml would render something like:

`authors = ["bar <<foo@baz>>"]`

instead of

`authors = ["bar <foo@baz>"]`

This detects the emails that start and end with `<>` and removes them.
@bors
Copy link
Collaborator

bors commented Nov 1, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing bd32ba7 to master...

@bors bors merged commit 7d57948 into rust-lang:master Nov 1, 2018
@ehuss ehuss added this to the 1.32.0 milestone Feb 6, 2022
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.

4 participants