Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a1fe375e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a1fe375e
编写于
3月 21, 2013
作者:
S
Sato Hiroyuki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix 404 error while displaying json files.
It uses params[:id] instead of request.fullpath. It should fix #3132.
上级
f7ca6c50
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
6 addition
and
66 deletion
+6
-66
app/controllers/blame_controller.rb
app/controllers/blame_controller.rb
+0
-2
app/controllers/blob_controller.rb
app/controllers/blob_controller.rb
+0
-2
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+0
-1
lib/extracts_path.rb
lib/extracts_path.rb
+6
-19
spec/lib/extracts_path_spec.rb
spec/lib/extracts_path_spec.rb
+0
-42
未找到文件。
app/controllers/blame_controller.rb
浏览文件 @
a1fe375e
...
...
@@ -7,8 +7,6 @@ class BlameController < ProjectResourceController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:assign_ref_vars
def
show
@repo
=
@project
.
repo
@blame
=
Grit
::
Blob
.
blame
(
@repo
,
@commit
.
id
,
@path
)
...
...
app/controllers/blob_controller.rb
浏览文件 @
a1fe375e
...
...
@@ -7,8 +7,6 @@ class BlobController < ProjectResourceController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:assign_ref_vars
def
show
if
@tree
.
is_blob?
send_data
(
...
...
app/controllers/tree_controller.rb
浏览文件 @
a1fe375e
...
...
@@ -7,7 +7,6 @@ class TreeController < ProjectResourceController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:assign_ref_vars
before_filter
:edit_requirements
,
only:
[
:edit
,
:update
]
def
show
...
...
lib/extracts_path.rb
浏览文件 @
a1fe375e
...
...
@@ -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
(
i
nput
)
def
extract_ref
(
i
d
)
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.
...
...
spec/lib/extracts_path_spec.rb
浏览文件 @
a1fe375e
...
...
@@ -54,47 +54,5 @@ describe ExtractsPath do
extract_ref
(
'stable/CHANGELOG'
).
should
==
[
'stable'
,
'CHANGELOG'
]
end
end
context
"with a fullpath"
do
it
"extracts a valid branch"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG'
).
should
==
[
'foo/bar/baz'
,
'CHANGELOG'
]
end
it
"extracts a valid tag"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG'
).
should
==
[
'v2.0.0'
,
'CHANGELOG'
]
end
it
"extracts a valid commit SHA"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG'
).
should
==
[
'f4b14494ef6abf3d144c28e4af0c20143383e062'
,
'CHANGELOG'
]
end
it
"extracts a timestamp"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435'
).
should
==
[
'v2.0.0'
,
'CHANGELOG'
]
end
end
context
"with a fullpath and a relative_url_root"
do
before
do
Gitlab
.
config
.
gitlab
.
stub
(
relative_url_root:
'/relative'
)
end
it
"extracts a valid branch with relative_url_root"
do
extract_ref
(
'/relative/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG'
).
should
==
[
'foo/bar/baz'
,
'CHANGELOG'
]
end
it
"extracts a valid tag"
do
extract_ref
(
'/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG'
).
should
==
[
'v2.0.0'
,
'CHANGELOG'
]
end
it
"extracts a valid commit SHA"
do
extract_ref
(
'/relative/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG'
).
should
==
[
'f4b14494ef6abf3d144c28e4af0c20143383e062'
,
'CHANGELOG'
]
end
it
"extracts a timestamp"
do
extract_ref
(
'/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435'
).
should
==
[
'v2.0.0'
,
'CHANGELOG'
]
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录