spoom 1.8.8 → 1.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f156e3fd1596713d8fb893ba5e4e0cdc127fc9ee1a21006c751773178e4eb1d3
4
- data.tar.gz: 84ce5c28958b0fe1b45251336dc283e005738b3c0d280a7f8cb5b643d4b8e8da
3
+ metadata.gz: 97cf397397aa58c2322089f795e390e7b7946445966fc341dd6a8566ae9b8ded
4
+ data.tar.gz: e42da92b60a476c7ed03116b9ce1c780fc59ec133b02ed73a6f501a0bb162359
5
5
  SHA512:
6
- metadata.gz: 98c8db47ce06755ac7ca5b3426f4f0413d611297240f28d19e767f3c76230c5ed963f54e51b092b6d5361f41b4c7a000423355ef4d4eb445d6ebe334c870c5f5
7
- data.tar.gz: 4c7a33cef72bc373fe5f7bd9f3230669d301baab006a26f5ce7c0483d627e3dd01e30b5a215282d3c537c77b10b5cc20eff739259bec6bfbb55851b6a654eb39
6
+ metadata.gz: eefa8467cecb02ee37700b60ba0d6570e90650a3a148992aeecf42e605ea51a787dfa4e0b08c31ae4c48f26b715bd13a21aba40197f10f63dfeef935378399e9
7
+ data.tar.gz: ae699ed2ce340106b923744a6b3583fe32c6ecd67c8b8dca16d750d32f2c13e95c0d11a11410d8587852d1a77caedd974f88ba18cd3a21166486114bacc3135e
@@ -158,7 +158,7 @@ module Spoom
158
158
  new_source = remover.remove_location(nil, location)
159
159
  context.write!("PATCH", new_source)
160
160
 
161
- diff = context.exec("diff -u #{location.file} PATCH")
161
+ diff = context.exec("diff -u #{location.file.shellescape} PATCH")
162
162
  $stderr.puts T.must(diff.out.lines[2..-1]).join
163
163
  context.remove!("PATCH")
164
164
 
@@ -1,6 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "shellwords"
5
+
4
6
  module Spoom
5
7
  module Git
6
8
  class Commit
@@ -52,7 +54,7 @@ module Spoom
52
54
  #: (?branch: String?) -> ExecResult
53
55
  def git_init!(branch: nil)
54
56
  if branch
55
- git("init -b #{branch}")
57
+ git("init -b #{branch.shellescape}")
56
58
  else
57
59
  git("init")
58
60
  end
@@ -61,16 +63,16 @@ module Spoom
61
63
  # Run `git checkout` in this context directory
62
64
  #: (?ref: String) -> ExecResult
63
65
  def git_checkout!(ref: "main")
64
- git("checkout #{ref}")
66
+ git("checkout #{ref.shellescape}")
65
67
  end
66
68
 
67
69
  # Run `git checkout -b <branch-name> <ref>` in this context directory
68
70
  #: (String branch_name, ?ref: String?) -> ExecResult
69
71
  def git_checkout_new_branch!(branch_name, ref: nil)
70
72
  if ref
71
- git("checkout -b #{branch_name} #{ref}")
73
+ git("checkout -b #{branch_name.shellescape} #{ref.shellescape}")
72
74
  else
73
- git("checkout -b #{branch_name}")
75
+ git("checkout -b #{branch_name.shellescape}")
74
76
  end
75
77
  end
76
78
 
@@ -79,10 +81,10 @@ module Spoom
79
81
  def git_commit!(message: "message", time: Time.now.utc, allow_empty: false)
80
82
  git("add --all")
81
83
 
82
- args = ["-m '#{message}'", "--date '#{time}'"]
84
+ args = ["-m #{message.shellescape}", "--date #{time.to_s.shellescape}"]
83
85
  args << "--allow-empty" if allow_empty
84
86
 
85
- exec("GIT_COMMITTER_DATE=\"#{time}\" git -c commit.gpgsign=false commit #{args.join(" ")}")
87
+ exec("GIT_COMMITTER_DATE=#{time.to_s.shellescape} git -c commit.gpgsign=false commit #{args.join(" ")}")
86
88
  end
87
89
 
88
90
  # Get the current git branch in this context directory
@@ -120,7 +122,7 @@ module Spoom
120
122
  # Run `git push <remote> <ref>` in this context directory
121
123
  #: (String remote, String ref, ?force: bool) -> ExecResult
122
124
  def git_push!(remote, ref, force: false)
123
- git("push #{force ? "-f" : ""} #{remote} #{ref}")
125
+ git("push #{force ? "-f" : ""} #{remote.shellescape} #{ref.shellescape}")
124
126
  end
125
127
 
126
128
  #: (*String arg) -> ExecResult
@@ -1,6 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "open3"
5
+
4
6
  module Spoom
5
7
  class FileCollector
6
8
  #: Array[String]
@@ -94,7 +96,15 @@ module Spoom
94
96
  #: (String path) -> String?
95
97
  def mime_type_for(path)
96
98
  # The `file` command appears to be hanging on MacOS for some files so we timeout after 1s.
97
- %x{timeout 1s file --mime-type -b '#{path}'}.split("; ").first&.strip
99
+ #
100
+ # The arguments are passed straight to the process instead of being interpolated into a
101
+ # shell command: `path` comes from the scanned directory, so a crafted file name could
102
+ # escape any quoting we applied ourselves and run as a command.
103
+ out, _status = Open3.capture2("timeout", "1s", "file", "--mime-type", "-b", path)
104
+ out.split("; ").first&.strip
105
+ rescue Errno::ENOENT
106
+ # `timeout` isn't part of a stock MacOS install. The shell used to swallow that for us.
107
+ nil
98
108
  end
99
109
  end
100
110
  end
data/lib/spoom/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Spoom
5
- VERSION = "1.8.8"
5
+ VERSION = "1.8.9"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.8
4
+ version: 1.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa