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

docs: add stdlib env::var(_os) panic #63461

Merged
merged 1 commit into from
Aug 12, 2019
Merged

Conversation

tommilligan
Copy link
Contributor

Closes #63456

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 11, 2019
///
/// This function may panic if `key` is empty, contains an ASCII equals sign
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL
/// character.
Copy link
Member

Choose a reason for hiding this comment

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

NUL character is repeated twice in both of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copied verbatim from the underlying functions called, which state they may crash when either the key or the value contain a null byte.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I missed the key/value distinction.

@Mark-Simulacrum
Copy link
Member

r? @alexcrichton

@joshtriplett
Copy link
Member

This looks great to me.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 12, 2019

📌 Commit af5625d has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 12, 2019
Centril added a commit to Centril/rust that referenced this pull request Aug 12, 2019
…iplett

docs: add stdlib env::var(_os) panic

Closes rust-lang#63456
bors added a commit that referenced this pull request Aug 12, 2019
Rollup of 10 pull requests

Successful merges:

 - #62108 (Use sharded maps for queries)
 - #63297 (Improve pointer offset method docs)
 - #63306 (Adapt AddRetag for shallow retagging)
 - #63406 (Suggest using a qualified path in patterns with inconsistent bindings)
 - #63431 (Revert "Simplify MIR generation for logical ops")
 - #63449 (resolve: Remove remaining special cases from built-in macros)
 - #63461 (docs: add stdlib env::var(_os) panic)
 - #63473 (Regression test for #56870)
 - #63474 (Add tests for issue #53598 and #57700)
 - #63480 (Fixes #63477)

Failed merges:

r? @ghost
@@ -182,6 +182,12 @@ impl fmt::Debug for VarsOs {
/// * Environment variable is not present
/// * Environment variable is not valid unicode
///
/// # Panics
///
/// This function may panic if `key` is empty, contains an ASCII equals sign

Choose a reason for hiding this comment

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

Is it "may panic" or "panics" (definitive)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function relies on std::sys::os, so the behaviour differs by operating system. We could update the docs to make this clearer.

Choose a reason for hiding this comment

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

Hmm, I'm not sure what is the practice in this case. Maybe "may" is fine.

BTW, I do wonder why this behavior was chosen, that if key contains a nul then it panics. It makes sense for setting a var, but when getting, it makes more sense to me that it just return None. The code comment in the unix implementation seems to agree, I think..

// environment variables with a nul byte can't be set, so their value is
// always None as well
let k = CString::new(k.as_bytes())?;

Centril added a commit to Centril/rust that referenced this pull request Aug 12, 2019
…iplett

docs: add stdlib env::var(_os) panic

Closes rust-lang#63456
bors added a commit that referenced this pull request Aug 12, 2019
Rollup of 9 pull requests

Successful merges:

 - #62108 (Use sharded maps for queries)
 - #63297 (Improve pointer offset method docs)
 - #63406 (Suggest using a qualified path in patterns with inconsistent bindings)
 - #63431 (Revert "Simplify MIR generation for logical ops")
 - #63449 (resolve: Remove remaining special cases from built-in macros)
 - #63461 (docs: add stdlib env::var(_os) panic)
 - #63473 (Regression test for #56870)
 - #63474 (Add tests for issue #53598 and #57700)
 - #63480 (Fixes #63477)

Failed merges:

r? @ghost
@@ -182,6 +182,12 @@ impl fmt::Debug for VarsOs {
/// * Environment variable is not present
/// * Environment variable is not valid unicode
///
/// # Panics
///
/// This function may panic if `key` is empty, contains an ASCII equals sign

Choose a reason for hiding this comment

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

Another question: the function documentation says that when key is not present, an error is returned, not a panic. So is the "is empty" here correct?

@bors bors merged commit af5625d into rust-lang:master Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std::env::var and std::env::var_os do not document panic on key containing null byte
7 participants