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

Better handle shebangs with = after the interpreter #4485

Merged
merged 2 commits into from
Apr 4, 2019

Conversation

lildude
Copy link
Member

@lildude lildude commented Apr 4, 2019

Description

As pointed out in #4447, the shebang strategy is a little over enthusiastic when it comes to parsing the shebang in a file if that shebang contains = after the interpreter resulting in the interpreter being completely missed and the file marked as plain text:

$ /bin/cat ~/tmp/trash/verbose-enigma/info
#!/usr/bin/env python -cos=__import__("os");sys=__import__("sys");python=os.path.join(os.path.dirname(sys.argv[1]),".lifx/bin/python");os.execv(python,sys.argv)

$
$ bundle exec github-linguist ~/tmp/trash/verbose-enigma/info
info: 2 lines (1 sloc)
  type:      Text
  mime type: text/plain
  language:

$

This PR addresses that by making the match for the preceding env vars tighter and then iterating over that match to catch them all, before moving onto the interpreter.

Now the same check gives us the correct interpreter:

$ /bin/cat ~/tmp/trash/verbose-enigma/info
#!/usr/bin/env python -cos=__import__("os");sys=__import__("sys");python=os.path.join(os.path.dirname(sys.argv[1]),".lifx/bin/python");os.execv(python,sys.argv)

$
$ bundle exec github-linguist ~/tmp/trash/verbose-enigma/info
info: 2 lines (1 sloc)
  type:      Text
  mime type: text/plain
  language:  Python
$

... and works if we put env vars before the interpreter too:

$ /bin/cat ~/tmp/trash/verbose-enigma/info
#!/usr/bin/env foo=bar bar=foo python -cos=__import__("os");sys=__import__("sys");python=os.path.join(os.path.dirname(sys.argv[1]),".lifx/bin/python");os.execv(python,sys.argv)

$
$ bundle exec github-linguist ~/tmp/trash/verbose-enigma/info
info: 2 lines (1 sloc)
  type:      Text
  mime type: text/plain
  language:  Python
$

Kudos to @pchaigno for the simple solution. 🙇

Checklist:

  • I am adding new or changing current functionality
    • I have added or updated the tests for the new or changed functionality.

Fixes #4447

@lildude lildude changed the title Lildude/handle shebang with equals Better handle shebangs with = after the interpreter Apr 4, 2019
@lildude lildude merged commit 45edb98 into master Apr 4, 2019
@lildude lildude deleted the lildude/handle-shebang-with-equals branch April 4, 2019 12:00
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shebang detection when arguments to the shebang have a = in them
2 participants