Skip to content

A platform for community discussion. Free, open, simple.

DEV: Further improvements to manual backport instructions (#40699)

David Taylor30dcb8c33daf
diff --git a/script/backport.rb b/script/backport.rb
index aedba63021d..481eb6797ca 100644
--- a/script/backport.rb
+++ b/script/backport.rb
@@ -2,7 +2,6 @@
require "json"
require "open3"
-require "shellwords"
RunResult = Data.define(:success, :stdout, :stderr)
@@ -19,6 +18,13 @@ def gh(*args, allow_failure: false)
run("gh", *args, allow_failure: allow_failure)
end
+# Quote a string as a single-line bash argument using ANSI-C ($'...') quoting,
+# so embedded newlines become a literal \n instead of wrapping the command.
+def bash_quote(str)
+ escaped = str.gsub(/[\\'\n]/, "\\" => "\\\\", "'" => "\\'", "\n" => "\\n")
+ "$'#{escaped}'"
+end
+
pr_number = ENV.fetch("PR_NUMBER")
# Get PR details (title, body, base branch)
@@ -205,8 +211,7 @@ if failed.any?
if r[:cherry_pick_range]
gh_create =
"gh pr create --base #{r[:release_branch]} --head #{r[:backport_branch]} " \
- "--title #{Shellwords.escape(r[:backport_title])} " \
- "--body #{Shellwords.escape(r[:backport_body])}"
+ "--title #{bash_quote(r[:backport_title])} --body #{bash_quote(r[:backport_body])}"
comment_lines << <<~MSG
#### #{r[:version]}