Skip to content

Commit 8f3147b

Browse files
committed
Rely on Shellwords.shellescape to escape
1 parent 7782fb5 commit 8f3147b

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

Diff for: spec/spec_helper_acceptance_local.rb

+1-21
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,5 @@ def postgresql_version
3737

3838
def psql(psql_cmd, user = 'postgres', exit_codes = [0, 1], &block)
3939
psql = "psql #{psql_cmd}"
40-
LitmusHelper.instance.run_shell("cd /tmp; su #{shellescape(user)} -c #{shellescape(psql)}", acceptable_exit_codes: exit_codes, &block)
41-
end
42-
43-
def shellescape(str)
44-
str = str.to_s
45-
46-
# An empty argument will be skipped, so return empty quotes.
47-
return "''" if str.empty?
48-
49-
str = str.dup
50-
51-
# Treat multibyte characters as is. It is caller's responsibility
52-
# to encode the string in the right encoding for the shell
53-
# environment.
54-
str.gsub!(%r{([^A-Za-z0-9_\-.,:/@\n])}, '\\\\\\1')
55-
56-
# A LF cannot be escaped with a backslash because a backslash + LF
57-
# combo is regarded as line continuation and simply ignored.
58-
str.gsub!(%r{\n}, "'\n'")
59-
60-
str
40+
LitmusHelper.instance.run_shell("cd /tmp; su #{Shellwords.shellescape(user)} -c #{Shellwords.shellescape(psql)}", acceptable_exit_codes: exit_codes, &block)
6141
end

0 commit comments

Comments
 (0)