Skip to content

Commit

Permalink
Merge pull request #1114 from alanoliveira/main
Browse files Browse the repository at this point in the history
prevent escape '#' when generating env_file string
  • Loading branch information
djmb authored Oct 23, 2024
2 parents bd8c35b + a3f5830 commit 0f97e0b
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 0f97e0b

Please sign in to comment.