summaryrefslogtreecommitdiff
path: root/lib/extracts_path.rb
diff options
context:
space:
mode:
authorSato Hiroyuki <sathiroyuki@gmail.com>2013-03-21 14:41:16 +0000
committerSato Hiroyuki <sathiroyuki@gmail.com>2013-03-21 15:10:14 +0000
commita1fe375e44987d89b9f9fbacb784eed83de233b2 (patch)
tree569d9db493584db0f19cc176f73f40b52873b7b5 /lib/extracts_path.rb
parentf7ca6c5079bb3c79c709721dae06b77200a1972e (diff)
downloadgitlab-ce-a1fe375e44987d89b9f9fbacb784eed83de233b2.tar.gz
Fix 404 error while displaying json files.
It uses params[:id] instead of request.fullpath. It should fix #3132.
Diffstat (limited to 'lib/extracts_path.rb')
-rw-r--r--lib/extracts_path.rb25
1 files changed, 6 insertions, 19 deletions
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 66b2f450545..351fc2f23ae 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -8,7 +8,7 @@ module ExtractsPath
included do
if respond_to?(:before_filter)
- before_filter :assign_ref_vars, only: [:show]
+ before_filter :assign_ref_vars
end
end
@@ -33,7 +33,7 @@ module ExtractsPath
# extract_ref("v2.0.0/README.md")
# # => ['v2.0.0', 'README.md']
#
- # extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb')
+ # extract_ref('master/app/models/project.rb')
# # => ['master', 'app/models/project.rb']
#
# extract_ref('issues/1234/app/models/project.rb')
@@ -45,22 +45,12 @@ module ExtractsPath
#
# Returns an Array where the first value is the tree-ish and the second is the
# path
- def extract_ref(input)
+ def extract_ref(id)
pair = ['', '']
return pair unless @project
- # Remove relative_url_root from path
- input.gsub!(/^#{Gitlab.config.gitlab.relative_url_root}/, "")
- # Remove project, actions and all other staff from path
- input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "")
- input.gsub!(/^\/(tree|commits|blame|blob|refs|graph)\//, "") # remove actions
- input.gsub!(/\?.*$/, "") # remove stamps suffix
- input.gsub!(/.atom$/, "") # remove rss feed
- input.gsub!(/.json$/, "") # remove json suffix
- input.gsub!(/\/edit$/, "") # remove edit route part
-
- if input.match(/^([[:alnum:]]{40})(.+)/)
+ if id.match(/^([[:alnum:]]{40})(.+)/)
# If the ref appears to be a SHA, we're done, just split the string
pair = $~.captures
else
@@ -68,7 +58,6 @@ module ExtractsPath
# branches and tags
# Append a trailing slash if we only get a ref and no file path
- id = input
id += '/' unless id.ends_with?('/')
valid_refs = @project.repository.ref_names
@@ -105,11 +94,9 @@ module ExtractsPath
# Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref).
def assign_ref_vars
- path = CGI::unescape(request.fullpath.dup)
-
- @ref, @path = extract_ref(path)
+ @id = params[:id]
- @id = File.join(@ref, @path)
+ @ref, @path = extract_ref(@id)
# It is used "@project.repository.commits(@ref, @path, 1, 0)",
# because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.