Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ def compsys(to, name = File.basename($0)) # :nodoc:
to << "#compdef #{name}\n"
to << COMPSYS_HEADER
visit(:compsys, {}, {}) {|o, d|
to << %Q[ "#{o}[#{d.gsub(/[\\\"\[\]]/, '\\\\\&')}]" \\\n]
# Escape what zsh would expand inside the double quotes ($ and `), as
# well as the characters _arguments treats specially.
to << %Q[ "#{o}[#{d.gsub(/[\\\"\[\]$`]/, '\\\\\&')}]" \\\n]
}
to << " '*:file:_files' && return 0\n"
end
Expand Down
6 changes: 6 additions & 0 deletions test/optparse/test_zsh_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ def test_compsys
assert_match(/\"--bar\[\]\"/, compsys)
assert_match(/\"--for\[\]\"/, compsys)
end

def test_compsys_escapes_shell_expansion
@opt.define("--price", "costs $HOME and `date`") {}
compsys = @opt.compsys("", "zshcompsys")
assert_include(compsys, %q["--price[costs \\$HOME and \\`date\\`]"])
end
end
Loading