Repository navigation
Stop script arguments from running as code - #19486
Merged
Merged
Conversation
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
nu script.nu <args>andnu -c <commands> <args>turn the arguments into the source textmain <args>and parse it.escape_for_script_argquotes the arguments that would parse as something other than a plain word, but it missed three shapes, so they ran as code.Before and after
Script:
def main [--x, ...args] { $args | to json --raw }. Main is a481925.nu test.nu ...a 'b c'["a","b c"]["a","b c"]'--x;print INJECTED'INJECTED["--x;print INJECTED"]'--x;print INJECTED=1'INJECTED=1["--x;print INJECTED=1"]'--help;print INJECTED'INJECTED["--help;print INJECTED"]'o>' out.txt[]toout.txt["o>","out.txt"]'out+err>' out.txt[]toout.txt["out+err>","out.txt"]'e>>' out.txtout.txt["e>>","out.txt"]'...$env.PATH'(PATH=/usr/bin:/bin)["/usr/bin","/bin"]["...$env.PATH"]'0..$nu.pid'["0..248"]["0..$nu.pid"]'='parse_mismatch: expected right hand side of assignment["="]'&&'shell_andand["&&"]'a)'unbalanced_delimiter["a)"]--x b["b"]["b"]Script:
def main [p: path] { $p | to json --raw }.nu test.nu ......"../..""../.."'~/a$b'"/Users/me/a$b""/Users/me/a$b"Script:
def main [g: glob] { ls $g | get name | sort | to json --raw }, in a directory holdinga$1.txt,a$2.txt,a)1.txtanda)2.txt.nu test.nu ...'a$*.txt'["a$1.txt","a$2.txt"]["a$1.txt","a$2.txt"]'a)*.txt'unbalanced_delimiter["a)1.txt","a)2.txt"]User-facing changes (Release notes)
nu script.nu <args>andnu -c <commands> <args>running some arguments as code. An argument such as--help;print hi, a redirection such aso> file, or a variable read such as...$env.PATHor0..$nu.pidnow reachesmainas a string.=,&&, and arguments containing)no longer fail to parse.Additional notes
escape_for_script_argleaves flag names, redirections, and spreads unquoted #19484.'(','[', or"'"as arguments. #9939, which asks for binding arguments without re-parsing them. This PR keeps the re-parse and only quotes more.