-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
#! (shebang) stripping doesn't account for spaces. #70528
Comments
As I understood from the description, you are saying that
Please confirm if we are on same page. |
@ayushmishra2005 All of those sound correct, yeah |
…r=estebank Fix #! (shebang) stripping account space issue rust-lang#70528
Fixed by #71372. |
There are issues with the fix (and it didn't go through Crater), so I'm preparing a revert. |
@rustbot claim |
Shebang handling was too agressive in stripping out the first line in cases where it is actually _not_ a shebang, but instead, valid rust (rust-lang#70528). This is a second attempt at resolving this issue (the first attempt was flawed, for, among other reasons, causing an ICE in certain cases (rust-lang#71372, rust-lang#71471). The behavior is now codified by a number of UI tests, but simply: For the first line to be a shebang, the following must all be true: 1. The line must start with `#!` 2. The line must contain a non whitespace character after `#!` 3. The next character in the file, ignoring comments & whitespace must not be `[` I believe this is a strict superset of what we used to allow, so perhaps a crater run is unnecessary, but probably not a terrible idea.
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:In this third example, it also strips just the
#!
, breaking the attribute:The code responsible is this:
rust/src/librustc_lexer/src/lib.rs
Lines 156 to 160 in 8045865
It doesn't seem to account for any whitespace between the
!
and[
.I believe that we should allow any characters
c
wherec != '\n' && is_whitespace(c)
after the#!
, and determine whether this is a shebang, by the next character on the same line:[
, this is the start of an inner commentI 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.
cc @matklad @petrochenkov
This issue has been assigned to @rcoh via this comment.
The text was updated successfully, but these errors were encountered: