Skip to content

Commit 91d6c58

Browse files
authored
Allow underscores as valid characters in the project directory (#2281)
Per a discussion with Andrew (RC) and @matthewjchandler we should accept underscores in the path. Closes #2280
1 parent e157c12 commit 91d6c58

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

app/models/project.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,6 @@ def project_directory_pathname
253253
end
254254
end
255255

256-
# Ensure that the project directory is a valid path
257-
def safe_directory(directory)
258-
Project.safe_directory(directory)
259-
end
260-
261256
def log_elapsed(start_time, prefix, message)
262257
elapsed_time = Time.zone.now - start_time
263258
timing_info = "#{format('%.2f', elapsed_time)} s"

app/models/project_metadata.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def self.default_provisionality
4848
def self.safe_directory(directory)
4949
return "" if directory.nil?
5050

51-
# only alphanumeric characters and /
52-
directory.strip.gsub(/[^A-Za-z\d\/]/, "-")
51+
# only alphanumeric characters, underscores, and /
52+
directory.strip.gsub(/[^A-Za-z\d_\/]/, "-")
5353
end
5454

5555
attr_accessor(

spec/models/project_metadata_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,19 @@
117117
expect(project_metadata.title).to eq("title abc again")
118118
end
119119
end
120+
121+
describe "#safe_directory" do
122+
it "handles nil values" do
123+
expect(described_class.safe_directory(nil)).to eq ""
124+
end
125+
126+
it "honors dashes and underscores" do
127+
expect(described_class.safe_directory("abc_123")).to eq "abc_123"
128+
expect(described_class.safe_directory("abc-456")).to eq "abc-456"
129+
end
130+
131+
it "replaces unexpected characters with dashes" do
132+
expect(described_class.safe_directory("hello#world{x}")).to eq "hello-world-x-"
133+
end
134+
end
120135
end

0 commit comments

Comments
 (0)