Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit d0fb8b8

Browse files
liamnicholsm-ruhl
authored andcommitted
Ensure shell arguments are escaped properly
- Make each item in `cmd` an individual argument - Expand file paths before passing into shell command - Pass `cmd` as a variable length argument list (`*cmd`) - Update specs to include checks for expanded paths and escaped arguments
1 parent 2a4ac93 commit d0fb8b8

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

lib/fastlane/plugin/xcodegen/actions/xcodegen_action.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ def self.run(params)
1515
end)
1616

1717
cmd = ["xcodegen"]
18-
cmd << "--spec #{params[:spec]}" if params[:spec]
19-
cmd << "--project #{params[:project]}" if params[:project]
18+
cmd += ["--spec", File.expand_path(params[:spec])] if params[:spec]
19+
cmd += ["--project", File.expand_path(params[:project])] if params[:project]
2020
cmd << "--quiet" if params[:quiet]
2121
cmd << "--use-cache" if params[:use_cache]
22-
cmd << "--cache-path #{params[:cache_path]}" if params[:cache_path]
23-
cmd << "--project-root #{params[:project_root]}" if params[:project_root]
22+
cmd += ["--cache-path", File.expand_path(params[:cache_path])] if params[:cache_path]
23+
cmd += ["--project-root", File.expand_path(params[:project_root])] if params[:project_root]
2424

25-
Actions.sh(cmd.join(' '))
25+
Actions.sh(*cmd)
2626
end
2727

2828
def self.description

spec/xcodegen_action_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
end
1818
it "sets the project param" do
1919
result = Fastlane::FastFile.new.parse("lane :test do
20-
xcodegen(project: '/tmp/Project.xcodeproj')
20+
xcodegen(project: '/tmp/My Project.xcodeproj')
2121
end").runner.execute(:test)
2222

23-
expect(result).to eq("xcodegen --project /tmp/Project.xcodeproj")
23+
expect(result).to eq('xcodegen --project /tmp/My\ Project.xcodeproj')
2424
end
2525
it "sets the quiet param" do
2626
result = Fastlane::FastFile.new.parse("lane :test do
@@ -41,14 +41,15 @@
4141
xcodegen(cache_path: '~/.xcodegen/cache/MyProject')
4242
end").runner.execute(:test)
4343

44-
expect(result).to eq("xcodegen --cache-path ~/.xcodegen/cache/MyProject")
44+
cache_path = File.expand_path("~/.xcodegen/cache/MyProject")
45+
expect(result).to eq("xcodegen --cache-path #{cache_path}")
4546
end
4647
it "sets the project-root param" do
4748
result = Fastlane::FastFile.new.parse("lane :test do
48-
xcodegen(project_root: '../')
49+
xcodegen(project_root: '/tmp/project-root')
4950
end").runner.execute(:test)
5051

51-
expect(result).to eq("xcodegen --project-root ../")
52+
expect(result).to eq("xcodegen --project-root /tmp/project-root")
5253
end
5354
it "ignores the quiet and use-cache params if false" do
5455
result = Fastlane::FastFile.new.parse("lane :test do

0 commit comments

Comments
 (0)