Repository navigation
Description
A file containing only this correctly errors:
#![bad_attribute]But this doesn't error, as it's stripped the same way #!/usr/bin/env ... (i.e. "shebang") would be:
#! [bad_attribute]In this third example, it also strips just the #!, breaking the attribute:
#!
[bad_attribute]The code responsible is this:
rust/src/librustc_lexer/src/lib.rs
Lines 156 to 160 in 8045865
| /// Line won't be skipped if it represents a valid Rust syntax | |
| /// (e.g. "#![deny(missing_docs)]"). | |
| pub fn strip_shebang(input: &str) -> Option<usize> { | |
| debug_assert!(!input.is_empty()); | |
| if !input.starts_with("#!") || input.starts_with("#![") { |
It doesn't seem to account for any whitespace between the ! and [.
I believe that we should allow any characters c where c != '\n' && is_whitespace(c) after the #!, and determine whether this is a shebang, by the next character on the same line:
- if there are no non-whitespace characters, it's not a valid shebang
- if the next character is
[, this is the start of an inner comment - otherwise, it's probably a shebang
I have no idea what to do for Rust comment syntax (#!//... and #!/*...), however.
And, of course, at the end of the day, this might be a backwards-incompatible change to make.
This issue has been assigned to @rcoh via this comment.
Activity
ayushmishra2005 commentedon Apr 18, 2020
@eddyb
As I understood from the description, you are saying that
This errors should also come for
#! [bad_attribute].#! /usr/bin/endshould also be considered as valid shebang and Rust compiler will skip this line.no changes for the third scenario:
#!
[bad_attribute]
Please confirm if we are on same page.
eddyb commentedon Apr 18, 2020
@ayushmishra2005 All of those sound correct, yeah
ayushmishra2005 commentedon Apr 19, 2020
Thanks @eddyb . I would like to pick this issue.
@rustbot claim
Fix #! (shebang) stripping account space issue rust-lang#70528
Refactoring and added test-cases rust-lang#70528
Rollup merge of rust-lang#71372 - ayushmishra2005:shebang_stripping, …
JohnTitor commentedon Apr 22, 2020
Fixed by #71372.
eddyb commentedon Apr 28, 2020
There are issues with the fix (and it didn't go through Crater), so I'm preparing a revert.
rcoh commentedon May 9, 2020
@rustbot claim
Fix bug in shebang handling