diff options
-rw-r--r-- | app/views/projects/artifacts/_tree_file.html.haml | 2 | ||||
-rw-r--r-- | config/routes.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/build/artifacts/metadata.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/ci/build/artifacts/metadata/entry.rb | 4 |
4 files changed, 17 insertions, 10 deletions
diff --git a/app/views/projects/artifacts/_tree_file.html.haml b/app/views/projects/artifacts/_tree_file.html.haml index 1d3d9306aa6..92c1648f726 100644 --- a/app/views/projects/artifacts/_tree_file.html.haml +++ b/app/views/projects/artifacts/_tree_file.html.haml @@ -6,6 +6,6 @@ %td = number_to_human_size(file.metadata[:size], precision: 2) %td - = link_to file_namespace_project_build_artifacts_path(path: file.path), + = link_to file_namespace_project_build_artifacts_path(@project.namespace, @project, @build, path: file.path), class: 'btn btn-xs btn-default artifact-download' do = icon('download') diff --git a/config/routes.rb b/config/routes.rb index d7fb7407794..0a29782f55b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -609,8 +609,8 @@ Rails.application.routes.draw do resource :artifacts, only: [] do get :download - get :browse, path: 'browse(/*path)', action: :browse, format: false - get :file, path: 'file/*path', action: :file, format: false + get :browse, path: 'browse(/*path)', format: false + get :file, path: 'file/*path', format: false end end diff --git a/lib/gitlab/ci/build/artifacts/metadata.rb b/lib/gitlab/ci/build/artifacts/metadata.rb index 25ecf27d4e6..1344f5d120b 100644 --- a/lib/gitlab/ci/build/artifacts/metadata.rb +++ b/lib/gitlab/ci/build/artifacts/metadata.rb @@ -6,6 +6,8 @@ module Gitlab module Build module Artifacts class Metadata + class ParserError < StandardError; end + VERSION_PATTERN = /^[\w\s]+(\d+\.\d+\.\d+)/ INVALID_PATH_PATTERN = %r{(^\.?\.?/)|(/\.?\.?/)} @@ -24,8 +26,13 @@ module Gitlab gzip do |gz| read_string(gz) # version errors = read_string(gz) - raise StandardError, 'Errors field not found!' unless errors - JSON.parse(errors) + raise ParserError, 'Errors field not found!' unless errors + + begin + JSON.parse(errors) + rescue JSON::ParserError + raise ParserError, 'Invalid errors field!' + end end end @@ -56,7 +63,7 @@ module Gitlab next unless path =~ match_pattern next if path =~ INVALID_PATH_PATTERN - entries.store(path, JSON.parse(meta, symbolize_names: true)) + entries[path] = JSON.parse(meta, symbolize_names: true) rescue JSON::ParserError, Encoding::CompatibilityError next end @@ -70,11 +77,11 @@ module Gitlab version_string = read_string(gz) unless version_string - raise StandardError, 'Artifacts metadata file empty!' + raise ParserError, 'Artifacts metadata file empty!' end unless version_string =~ VERSION_PATTERN - raise StandardError, 'Invalid version!' + raise ParserError, 'Invalid version!' end version_string.chomp diff --git a/lib/gitlab/ci/build/artifacts/metadata/entry.rb b/lib/gitlab/ci/build/artifacts/metadata/entry.rb index 4dae02ce4f7..25b71fc3275 100644 --- a/lib/gitlab/ci/build/artifacts/metadata/entry.rb +++ b/lib/gitlab/ci/build/artifacts/metadata/entry.rb @@ -57,7 +57,7 @@ module Gitlab return @children if @children child_pattern = %r{^#{Regexp.escape(@path)}[^/]+/?$} - @children = select_entries { |entry| entry =~ child_pattern } + @children = select_entries { |path| path =~ child_pattern } end def directories(opts = {}) @@ -110,7 +110,7 @@ module Gitlab private def select_entries - selected = @entries.select { |entry, _metadata| yield entry } + selected = @entries.select { |path, _metadata| yield path } selected.map { |path, _metadata| self.class.new(path, @entries) } end end |