about summary refs log tree commit diff
path: root/lib/tasks
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-02-29 12:50:44 +0100
committerGitHub <noreply@github.com>2020-02-29 12:50:44 +0100
commit907ebcfd43c7c051de831944a29620580fa8faa5 (patch)
tree6c00f4972e86f44ba1899385eb107838d146e5c1 /lib/tasks
parente1d29f7d9f85a25af7a1595d2c9afc127ab36ca7 (diff)
parent427ef4948a4fdd1c34e7c7baa6dd5c967e32d932 (diff)
Merge pull request #1291 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/mastodon.rake15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 2e92e8ded..a873335d4 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -336,7 +336,20 @@ namespace :mastodon do
       if prompt.yes?('Save configuration?')
         cmd = TTY::Command.new(printer: :quiet)
 
-        File.write(Rails.root.join('.env.production'), "# Generated with mastodon:setup on #{Time.now.utc}\n\n" + env.each_pair.map { |key, value| "#{key}=#{value}" }.join("\n") + "\n")
+        env_contents = env.each_pair.map do |key, value|
+          if value.is_a?(String) && value =~ /[\s\#\\"]/
+            if value =~ /[']/
+              value = value.to_s.gsub(/[\\"\$]/) { |x| "\\#{x}" }
+              "#{key}=\"#{value}\""
+            else
+              "#{key}='#{value}'"
+            end
+          else
+            "#{key}=#{value}"
+          end
+        end.join("\n")
+
+        File.write(Rails.root.join('.env.production'), "# Generated with mastodon:setup on #{Time.now.utc}\n\n" + env_contents + "\n")
 
         if using_docker
           prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:'