Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
2723dea6
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 搜索 >>
提交
2723dea6
编写于
1月 18, 2016
作者:
R
Rémy Coutable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure Gravatar host looks like an actual host
上级
f603f3b3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
8 deletion
+59
-8
CHANGELOG
CHANGELOG
+1
-0
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+14
-8
spec/initializers/settings_spec.rb
spec/initializers/settings_spec.rb
+44
-0
未找到文件。
CHANGELOG
浏览文件 @
2723dea6
Please view this file on the master branch, on stable branches it's out of date.
v 8.4.0 (unreleased)
- Ensure Gravatar host looks like an actual host
- Add pagination headers to already paginated API resources
- Properly generate diff of orphan commits, like the first commit in a repository
- Improve the consistency of commit titles, branch names, tag names, issue/MR titles, on their respective project pages
...
...
config/initializers/1_settings.rb
浏览文件 @
2723dea6
...
...
@@ -9,13 +9,8 @@ class Settings < Settingslogic
gitlab
.
port
.
to_i
==
(
gitlab
.
https
?
443
:
80
)
end
# get host without www, thanks to http://stackoverflow.com/a/6674363/1233435
def
get_host_without_www
(
url
)
url
=
CGI
.
escape
(
url
)
uri
=
URI
.
parse
(
url
)
uri
=
URI
.
parse
(
"http://
#{
url
}
"
)
if
uri
.
scheme
.
nil?
host
=
uri
.
host
.
downcase
host
.
start_with?
(
'www.'
)
?
host
[
4
..-
1
]
:
host
def
host_without_www
(
url
)
host
(
url
).
sub
(
'www.'
,
''
)
end
def
build_gitlab_ci_url
...
...
@@ -87,6 +82,17 @@ class Settings < Settingslogic
custom_port
]
end
# Extract the host part of the given +url+.
def
host
(
url
)
url
=
url
.
downcase
url
=
"http://
#{
url
}
"
unless
url
.
start_with?
(
'http'
)
# Get rid of the path so that we don't even have to encode it
url_without_path
=
url
.
sub
(
%r{(https?://[^
\/
]+)/?.*}
,
'\1'
)
URI
.
parse
(
url_without_path
).
host
end
end
end
...
...
@@ -228,7 +234,7 @@ Settings['gravatar'] ||= Settingslogic.new({})
Settings
.
gravatar
[
'enabled'
]
=
true
if
Settings
.
gravatar
[
'enabled'
].
nil?
Settings
.
gravatar
[
'plain_url'
]
||=
'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
Settings
.
gravatar
[
'ssl_url'
]
||=
'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
Settings
.
gravatar
[
'host'
]
=
Settings
.
get_
host_without_www
(
Settings
.
gravatar
[
'plain_url'
])
Settings
.
gravatar
[
'host'
]
=
Settings
.
host_without_www
(
Settings
.
gravatar
[
'plain_url'
])
#
# Cron Jobs
...
...
spec/initializers/settings_spec.rb
0 → 100644
浏览文件 @
2723dea6
require_relative
'../../config/initializers/1_settings'
describe
Settings
,
lib:
true
do
describe
'#host_without_www'
do
context
'URL with protocol'
do
it
'returns the host'
do
expect
(
Settings
.
host_without_www
(
'http://foo.com'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'http://www.foo.com'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'http://secure.foo.com'
)).
to
eq
'secure.foo.com'
expect
(
Settings
.
host_without_www
(
'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
)).
to
eq
'gravatar.com'
expect
(
Settings
.
host_without_www
(
'https://foo.com'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'https://www.foo.com'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'https://secure.foo.com'
)).
to
eq
'secure.foo.com'
expect
(
Settings
.
host_without_www
(
'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
)).
to
eq
'secure.gravatar.com'
end
end
context
'URL without protocol'
do
it
'returns the host'
do
expect
(
Settings
.
host_without_www
(
'foo.com'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'www.foo.com'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'secure.foo.com'
)).
to
eq
'secure.foo.com'
expect
(
Settings
.
host_without_www
(
'www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
)).
to
eq
'gravatar.com'
end
context
'URL with user/port'
do
it
'returns the host'
do
expect
(
Settings
.
host_without_www
(
'bob:pass@foo.com:8080'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'bob:pass@www.foo.com:8080'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'bob:pass@secure.foo.com:8080'
)).
to
eq
'secure.foo.com'
expect
(
Settings
.
host_without_www
(
'bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon'
)).
to
eq
'gravatar.com'
expect
(
Settings
.
host_without_www
(
'http://bob:pass@foo.com:8080'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'http://bob:pass@www.foo.com:8080'
)).
to
eq
'foo.com'
expect
(
Settings
.
host_without_www
(
'http://bob:pass@secure.foo.com:8080'
)).
to
eq
'secure.foo.com'
expect
(
Settings
.
host_without_www
(
'http://bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon'
)).
to
eq
'gravatar.com'
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录