Commit cd3b8bbd authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add method that checks if path exists in `StringPath`

parent a5e1905d
...@@ -17,7 +17,7 @@ class Projects::ArtifactsController < Projects::ApplicationController ...@@ -17,7 +17,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
def browse def browse
return render_404 unless build.artifacts? return render_404 unless build.artifacts?
@path = build.artifacts_metadata_string_path(params[:path] || './') @path = build.artifacts_metadata_string_path(params[:path] || './')
return render_404 if @path.universe.empty? return render_404 unless @path.exists?
end end
private private
......
...@@ -19,6 +19,10 @@ module Gitlab ...@@ -19,6 +19,10 @@ module Gitlab
@path @path
end end
def exists?
@path == './' || @universe.include?(@path)
end
def absolute? def absolute?
@path.start_with?('/') @path.start_with?('/')
end end
......
...@@ -32,6 +32,7 @@ describe Gitlab::StringPath do ...@@ -32,6 +32,7 @@ describe Gitlab::StringPath do
it { is_expected.to be_file } it { is_expected.to be_file }
it { is_expected.to have_parent } it { is_expected.to have_parent }
it { is_expected.to_not have_descendants } it { is_expected.to_not have_descendants }
it { is_expected.to exist }
describe '#basename' do describe '#basename' do
subject { |example| path(example).basename } subject { |example| path(example).basename }
...@@ -170,4 +171,16 @@ describe Gitlab::StringPath do ...@@ -170,4 +171,16 @@ describe Gitlab::StringPath do
it { is_expected.to eq '/path/file1' } it { is_expected.to eq '/path/file1' }
end end
describe '#exists?', path: 'another_file' do
subject { |example| path(example).exists? }
it { is_expected.to be true }
end
describe '#exists?', path: './non_existent/' do
let(:universe) { ['./something'] }
subject { |example| path(example).exists? }
it { is_expected.to be false }
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment