Skip to content

fix: improve shebang detection #74

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

Merged
merged 1 commit into from
Jul 14, 2023
Merged

Conversation

tomeon
Copy link
Collaborator

@tomeon tomeon commented Jul 14, 2023

in the following ways:

  1. Handle whitespace in between the "!#" and the executor/interpreter and between the executor/interpreter and other args,
  2. Handle the case where the first line of a script contains just "#!", and
  3. Handle multiple arguments (e.g., correctly detect that /usr/bin/env -S bash is a shell shebang).

Inspired by #73 , expanded to account for other shebang shenanigans. Also, tests.

in the following ways:

    1. Handle whitespace in between the "!#" and the
       executor/interpreter and between the executor/interpreter and
       other args,
    2. Handle the case where the first line of a script contains just
       "#!", and
    3. Handle multiple arguments (e.g., correctly detect that
       `/usr/bin/env -S bash` is a shell shebang).
@tomeon tomeon requested a review from infertux July 14, 2023 01:25
Copy link
Owner

@infertux infertux left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you for tackling that. I'm running ./test.sh locally and will merge the PR if it passes.

@@ -38,8 +38,6 @@ def shellscript?(filename)
(shellscript_extension?(filename) && shellscript_syntax?(filename))
end

private
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: #shellscript_syntax? could have been left as private since we don't call/test it directly but that doesn't really matter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops; happy to fix this.

end

it "returns true for shell interpreters" do
aggregate_failures "valid shebang handling" do
Copy link
Owner

Choose a reason for hiding this comment

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

TIL about aggregate_failures, nice :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see an application for aggregate_failures in the runner spec as well; PR incoming :)

@infertux infertux merged commit 5b1f893 into master Jul 14, 2023
@infertux infertux deleted the detective-shebang-handle-spaces branch July 14, 2023 04:00
This was referenced Jul 14, 2023
@infertux
Copy link
Owner

Just published Bashcov 3.0.3 with this fix, thank you!

@gszep
Copy link

gszep commented Jul 14, 2023

I'm geting

bashcov-3.0.3/lib/bashcov/detective.rb:61:in `scan': invalid byte sequence in UTF-8 (ArgumentError)
      return false if scanner.scan(/#!\s*/).nil?

because it is trying to read a .cpython-310-x86_64-linux-gnu.so file

@tomeon
Copy link
Collaborator Author

tomeon commented Jul 14, 2023

@gszep -- oh dear :(. If possible, would you kindly share the file that's triggering this error?

Nevermind; running the Bashcov test suite triggers this, too. 👀

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