diff --git a/lib/kamal/env_file.rb b/lib/kamal/env_file.rb index 6a4a80e3..36c251be 100644 --- a/lib/kamal/env_file.rb +++ b/lib/kamal/env_file.rb @@ -37,6 +37,8 @@ class Kamal::EnvFile def escape_docker_env_file_ascii_value(value) # Doublequotes are treated literally in docker env files # so remove leading and trailing ones and unescape any others - value.to_s.dump[1..-2].gsub(/\\"/, "\"") + value.to_s.dump[1..-2] + .gsub(/\\"/, "\"") + .gsub(/\\#/, "#") end end diff --git a/test/env_file_test.rb b/test/env_file_test.rb index c6b9e66e..34d31ad6 100644 --- a/test/env_file_test.rb +++ b/test/env_file_test.rb @@ -11,6 +11,16 @@ class EnvFileTest < ActiveSupport::TestCase Kamal::EnvFile.new(env).to_s end + test "to_s won't escape '#'" do + env = { + "foo" => '#$foo', + "bar" => '#{bar}' + } + + assert_equal "foo=\#$foo\nbar=\#{bar}\n", \ + Kamal::EnvFile.new(env).to_s + end + test "to_str won't escape chinese characters" do env = { "foo" => '你好 means hello, "欢迎" means welcome, that\'s simple! 😃 {smile}'