Skip to content

Commit

Permalink
fix #28188: filename lost in cmd interpolation (#37007)
Browse files Browse the repository at this point in the history
* fix 28188: filename lost in cmd interpolation

* move test to test/misc.jl

(cherry picked from commit 06b7f0b)
  • Loading branch information
simeonschaub authored and KristofferC committed Aug 13, 2020
1 parent 625bdf7 commit e438d0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,6 @@ Process(`echo 1`, ProcessExited(0))
```
"""
macro cmd(str)
return :(cmd_gen($(esc(shell_parse(str, special=shell_special)[1]))))
cmd_ex = shell_parse(str, special=shell_special, filename=String(__source__.file))[1]
return :(cmd_gen($(esc(cmd_ex))))
end
5 changes: 3 additions & 2 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function rstrip_shell(s::AbstractString)
end

function shell_parse(str::AbstractString, interpolate::Bool=true;
special::AbstractString="")
special::AbstractString="", filename="none")
s::SubString = SubString(str, firstindex(str))
s = rstrip_shell(lstrip(s))

Expand Down Expand Up @@ -69,7 +69,8 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
# string interpolation syntax (see #3150)
ex, j = :var, stpos+3
else
ex, j = Meta.parse(s,stpos,greedy=false)
# use parseatom instead of parse to respect filename (#28188)
ex, j = Meta.parseatom(s, stpos, filename=filename)
end
last_parse = (stpos:prevind(s, j)) .+ s.offset
update_arg(ex);
Expand Down
5 changes: 5 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,8 @@ end
@testset "fieldtypes Module" begin
@test fieldtypes(Module) isa Tuple
end


@testset "issue #28188" begin
@test `$(@__FILE__)` == let file = @__FILE__; `$file` end
end

0 comments on commit e438d0e

Please sign in to comment.