From 844e3acf50a9767611153866da07e9d000eb3376 Mon Sep 17 00:00:00 2001 From: Alan Oliveira Date: Tue, 15 Oct 2024 14:24:09 +0900 Subject: [PATCH] prevent escape '#' when generating env_file string --- lib/kamal/env_file.rb | 4 +++- test/env_file_test.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/kamal/env_file.rb b/lib/kamal/env_file.rb index 6a4a80e34..36c251be5 100644 --- a/lib/kamal/env_file.rb +++ b/lib/kamal/env_file.rb @@ -37,6 +37,8 @@ def escape_docker_env_file_value(value) 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 c6b9e66ec..263449346 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}'