Merge pull request #773 from xiaohui-zhangxh/docker-env-file-keep-non-ascii

don't escape non-ascii characters in docker env file
This commit is contained in:
Donal McBreen
2024-04-25 11:57:14 +01:00
committed by GitHub
5 changed files with 39 additions and 5 deletions

View File

@@ -24,6 +24,13 @@ class Kamal::EnvFile
# Escape a value to make it safe to dump in a docker file.
def escape_docker_env_file_value(value)
# keep non-ascii(UTF-8) characters as it is
value.to_s.scan(/[\x00-\x7F]+|[^\x00-\x7F]+/).map do |part|
part.ascii_only? ? escape_docker_env_file_ascii_value(part) : part
end.join
end
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(/\\"/, "\"")