Skip to content

Commit

Permalink
prevent escape '#' when generating env_file string
Browse files Browse the repository at this point in the history
  • Loading branch information
alanoliveira committed Oct 15, 2024
1 parent 6073681 commit 844e3ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/kamal/env_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions test/env_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down

0 comments on commit 844e3ac

Please sign in to comment.