Skip to content

Commit

Permalink
got rid of rc_quote
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dertuxmalwieder authored Nov 29, 2023
1 parent d26a408 commit 1c4c319
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions Library/Homebrew/utils/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def export_value(key, value, shell = preferred)
# and a literal \ can be included via \\
"set -gx #{key} \"#{sh_quote(value)}\""
when :rc
"#{key}=(#{rc_quote(value)})"
"#{key}=(#{sh_quote(value)})"
when :csh, :tcsh
"setenv #{key} #{csh_quote(value)};"
end
Expand Down Expand Up @@ -86,7 +86,7 @@ def prepend_path_in_profile(path)
when :bash, :ksh, :mksh, :sh, :zsh, nil
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{profile}"
when :rc
"echo 'path=(#{rc_quote(path)} $path)' >> #{profile}"
"echo 'path=(#{sh_quote(path)} $path)' >> #{profile}"
when :csh, :tcsh
"echo 'setenv PATH #{csh_quote(path)}:$PATH' >> #{profile}"
when :fish
Expand Down Expand Up @@ -134,19 +134,5 @@ def sh_quote(str)
str.gsub!(/\n/, "'\n'")
str
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

0 comments on commit 1c4c319

Please sign in to comment.