Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f682c097
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 搜索 >>
提交
f682c097
编写于
7月 12, 2016
作者:
D
Douglas Barbosa Alexandre
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix markdown rendering for label references that begin with a digit
上级
c88075f4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
1 deletion
+52
-1
app/models/label.rb
app/models/label.rb
+4
-1
spec/lib/banzai/filter/label_reference_filter_spec.rb
spec/lib/banzai/filter/label_reference_filter_spec.rb
+48
-0
未找到文件。
app/models/label.rb
浏览文件 @
f682c097
...
...
@@ -52,11 +52,14 @@ class Label < ActiveRecord::Base
# This pattern supports cross-project references.
#
def
self
.
reference_pattern
# NOTE: The id pattern only matches when all characters on the expression
# are digits, so it will match ~2 but not ~2fa because that's probably a
# label name and we want it to be matched as such.
@reference_pattern
||=
%r{
(
#{
Project
.
reference_pattern
}
)?
#{
Regexp
.
escape
(
reference_prefix
)
}
(?:
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_id>
\d
+
(?!
\S\w
)
\b
) | # Integer-based label ID, or
(?<label_name>
[A-Za-z0-9_
\-\?
&]+ | # String-based single-word label title, or
"([^"]*)" # String-based multi-word label surrounded in quotes
...
...
spec/lib/banzai/filter/label_reference_filter_spec.rb
浏览文件 @
f682c097
...
...
@@ -104,6 +104,30 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
context
'String-based single-word references that begin with a digit'
do
let
(
:label
)
{
create
(
:label
,
name:
'2fa'
,
project:
project
)
}
let
(
:reference
)
{
"
#{
Label
.
reference_prefix
}#{
label
.
name
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
expect
(
doc
.
text
).
to
eq
'See 2fa'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
#{
label
.
name
}
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
exp
=
act
=
"Label
#{
Label
.
reference_prefix
}#{
label
.
id
}#{
label
.
name
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'String-based single-word references with special characters'
do
let
(
:label
)
{
create
(
:label
,
name:
'?gfm&'
,
project:
project
)
}
let
(
:reference
)
{
"
#{
Label
.
reference_prefix
}#{
label
.
name
}
"
}
...
...
@@ -153,6 +177,30 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
context
'String-based multi-word references that begin with a digit'
do
let
(
:label
)
{
create
(
:label
,
name:
'2 factor authentication'
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
(
format: :name
)
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
expect
(
doc
.
text
).
to
eq
'See 2 factor authentication'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
#{
label
.
name
}
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
exp
=
act
=
"Label
#{
Label
.
reference_prefix
}#{
label
.
id
}#{
label
.
name
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'String-based multi-word references with special characters in quotes'
do
let
(
:label
)
{
create
(
:label
,
name:
'gfm & references?'
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
(
format: :name
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录