Escape strings for the shell
Some checks failed
CI / RuboCop (push) Has been cancelled
CI / Tests (Ruby 3.2) (push) Has been cancelled
CI / Tests (Ruby 3.3) (push) Has been cancelled
CI / Tests (Ruby 3.4) (push) Has been cancelled

Whitespaces in strings were interpreted by the shell as new words.
Escaping them ensures the shell sees the string as a single value.
This commit is contained in:
T. R. Bernstein
2025-08-29 23:53:32 +02:00
parent 2eed47d464
commit 7da03fd94c
2 changed files with 6 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
require "shellwords"
class Kamal::Commands::Builder::Base < Kamal::Commands::Base
class BuilderError < StandardError; end
@@ -44,7 +46,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
end
def build_context
config.builder.context
Shellwords.escape(config.builder.context)
end
def validate_image
@@ -92,7 +94,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
def build_dockerfile
if Pathname.new(File.expand_path(dockerfile)).exist?
argumentize "--file", dockerfile
argumentize "--file", Shellwords.escape(dockerfile)
else
raise BuilderError, "Missing #{dockerfile}"
end

View File

@@ -1,5 +1,6 @@
require "tempfile"
require "open3"
require "shellwords"
module Kamal::Docker
extend self
@@ -15,7 +16,7 @@ module Kamal::Docker
DOCKERFILE
dockerfile.close
cmd = "docker buildx build -t=#{BUILD_CHECK_TAG} -f=#{dockerfile.path} ."
cmd = "docker buildx build -t=#{BUILD_CHECK_TAG} -f=#{Shellwords.escape(dockerfile.path)} ."
system(cmd) || raise("failed to build check image")
end