Skip to content

Commit

Permalink
fix shell mode interpolation & allow special chars in commands
Browse files Browse the repository at this point in the history
fixes #22176, see also #20494 and #20482

(cherry picked from commit c49abd7)
ref #22413
  • Loading branch information
StefanKarpinski authored and tkelman committed Jun 18, 2017
1 parent 4a93542 commit 4e06773
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion base/REPL.jl
Expand Up @@ -750,7 +750,9 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
# and pass into Base.repl_cmd for processing (handles `ls` and `cd`
# special)
on_done = respond(repl, julia_prompt) do line
Expr(:call, :(Base.repl_cmd), Cmd(Base.shell_split(line)), outstream(repl))
Expr(:call, :(Base.repl_cmd),
:(Base.cmd_gen($(Base.shell_parse(line)[1]))),
outstream(repl))
end)


Expand Down
2 changes: 1 addition & 1 deletion base/REPLCompletions.jl
Expand Up @@ -586,7 +586,7 @@ function shell_completions(string, pos)
use_envpath = !ignore_last_word && length(args.args) < 2

return complete_path(prefix, pos, use_envpath=use_envpath)
elseif isexpr(arg, :escape) && (isexpr(arg.args[1], :incomplete) || isexpr(arg.args[1], :error))
elseif isexpr(arg, :incomplete) || isexpr(arg, :error)
r = first(last_parse):prevind(last_parse, last(last_parse))
partial = scs[r]
ret, range = completions(partial, endof(partial))
Expand Down
2 changes: 1 addition & 1 deletion base/process.jl
Expand Up @@ -793,7 +793,7 @@ function cmd_gen(parsed)
end

macro cmd(str)
return :(cmd_gen($(shell_parse(str, special=shell_special)[1])))
return :(cmd_gen($(esc(shell_parse(str, special=shell_special)[1]))))
end

wait(x::Process) = if !process_exited(x); stream_wait(x, x.exitnotify); end
Expand Down
2 changes: 1 addition & 1 deletion base/shell.jl
Expand Up @@ -75,7 +75,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
stpos = j
ex, j = parse(s,j,greedy=false)
last_parse = stpos:j
update_arg(esc(ex)); i = j
update_arg(ex); i = j
else
if !in_double_quotes && c == '\''
in_single_quotes = !in_single_quotes
Expand Down
18 changes: 18 additions & 0 deletions test/repl.jl
Expand Up @@ -124,6 +124,24 @@ if !is_windows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER
startswith(s, "\e[0m\e[1m\e[91mERROR: \e[39m\e[22m\e[91munterminated single quote\e[39m\nStacktrace:\n [1] ")
end

# issues #22176 & #20482
# TODO: figure out how to test this on Windows
is_windows() || let tmp = tempname()
try
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "echo \$123 >$tmp\n")
let s = readuntil(stdout_read, "\n")
@test contains(s, "shell> ") # make sure we echoed the prompt
@test contains(s, "echo \$123 >$tmp") # make sure we echoed the input
end
@test readuntil(stdout_read, "\n") == "\e[0m\n"
@test readstring(tmp) == "123\n"
finally
rm(tmp, force=true)
end
end

# Issue #7001
# Test ignoring '\0'
let
Expand Down

0 comments on commit 4e06773

Please sign in to comment.