got rid of rc_quote
The only "special" case about `rc` quoting is that strings that contain apostrophes need to contain double apostrophes instead. It seems unlikely that this will happen in Homebrew.
This commit is contained in:
parent
d26a408870
commit
1c4c3194e6
@ -43,7 +43,7 @@ module Utils
|
|||||||
# and a literal \ can be included via \\
|
# and a literal \ can be included via \\
|
||||||
"set -gx #{key} \"#{sh_quote(value)}\""
|
"set -gx #{key} \"#{sh_quote(value)}\""
|
||||||
when :rc
|
when :rc
|
||||||
"#{key}=(#{rc_quote(value)})"
|
"#{key}=(#{sh_quote(value)})"
|
||||||
when :csh, :tcsh
|
when :csh, :tcsh
|
||||||
"setenv #{key} #{csh_quote(value)};"
|
"setenv #{key} #{csh_quote(value)};"
|
||||||
end
|
end
|
||||||
@ -86,7 +86,7 @@ module Utils
|
|||||||
when :bash, :ksh, :mksh, :sh, :zsh, nil
|
when :bash, :ksh, :mksh, :sh, :zsh, nil
|
||||||
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{profile}"
|
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{profile}"
|
||||||
when :rc
|
when :rc
|
||||||
"echo 'path=(#{rc_quote(path)} $path)' >> #{profile}"
|
"echo 'path=(#{sh_quote(path)} $path)' >> #{profile}"
|
||||||
when :csh, :tcsh
|
when :csh, :tcsh
|
||||||
"echo 'setenv PATH #{csh_quote(path)}:$PATH' >> #{profile}"
|
"echo 'setenv PATH #{csh_quote(path)}:$PATH' >> #{profile}"
|
||||||
when :fish
|
when :fish
|
||||||
@ -134,19 +134,5 @@ module Utils
|
|||||||
str.gsub!(/\n/, "'\n'")
|
str.gsub!(/\n/, "'\n'")
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(str: String).returns(String) }
|
|
||||||
def rc_quote(str)
|
|
||||||
# ruby's implementation of shell_escape
|
|
||||||
str = str.to_s
|
|
||||||
return "''" if str.empty?
|
|
||||||
|
|
||||||
str = str.dup
|
|
||||||
# anything that isn't a known safe character is padded
|
|
||||||
str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") # rubocop:disable Style/StringConcatenation
|
|
||||||
str.gsub!(/'/, "''")
|
|
||||||
str.gsub!(/\n/, "'\n'")
|
|
||||||
str
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user