-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
nix-shell: support single quotes in shebangs, fix whitespace parsing #8470
Conversation
c59460e
to
ac7e219
Compare
I spotted another issue with the whitespace:
I might as well fix that too. |
ac7e219
to
dd8ac26
Compare
Should be good now. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-06-09-nix-team-meeting-minutes-61/29163/1 |
tests/shell.shebang.sh
Outdated
@@ -1,4 +1,4 @@ | |||
#! @ENV_PROG@ nix-shell | |||
#! nix-shell -I nixpkgs=shell.nix --no-substitute | |||
#! nix-shell --pure -i bash -p foo bar | |||
#! nix-shell --pure -i bash -p '(_: foo) "absurd"' "b\ar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test does not prove enough, because this works:
nix-repl> with { foo = true; }; (_: foo) absurd
true
What we need to see is that the parsed values are correct, including
"
in'
'
in"
- escaping
- concatenation, for example is this a valid way to handle a single quote in a single-quoted string?
does'It'"'"'s one string'
parse as a single string containingIt's one string
?
To test this effectively, I think it'd be best to find a way to echo a whole string and not just some variables. Maybe --argstr
could be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
406fa76
to
bf64b4b
Compare
Macos tests failing because of cachix/install-nix-action#183, need install-nix-action bump. Would be cool not to cancel the ubuntu tests on failure. |
bf64b4b
to
2978fc2
Compare
Does anything else need to be done here? |
I guess I can write a release note. |
2978fc2
to
3cc763d
Compare
Single quotes are a basic feature of shell syntax that people expect to work. They are also more convenient for writing literal code expressions with less escaping.
Leading whitespace after `nix-shell` used to produce an empty argument, while an empty argument at the end of the line was ignored. Fix the first issue by consuming the initial whitespace before calling shellwords; fix the second issue by returning immediately if whitespace is found at the end of the string instead of checking for an empty string. Also throw if quotes aren't terminated.
3cc763d
to
5f8e057
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now. Sorry for the delay!
5f8e057
to
e053eeb
Compare
nix-shell: support single quotes in shebangs, fix whitespace parsing (cherry picked from commit 3b99c62) Change-Id: I2a431b21c3467eefa1ef95d5a36d672f45b6937a
Motivation and context
Fixes #2356
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests
tests/nixos/*
Priorities
Add 👍 to pull requests you find important.