Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a59ad393
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,发现更多精彩内容 >>
提交
a59ad393
编写于
5月 05, 2016
作者:
T
Timothy Andrew
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a spec for `WikiLinkFilter`
- And fix behavior for non-file hierarchical links.
上级
f2251273
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
85 addition
and
3 deletion
+85
-3
lib/banzai/filter/wiki_link_filter.rb
lib/banzai/filter/wiki_link_filter.rb
+8
-3
spec/lib/banzai/filter/wiki_link_filter_spec.rb
spec/lib/banzai/filter/wiki_link_filter_spec.rb
+77
-0
未找到文件。
lib/banzai/filter/wiki_link_filter.rb
浏览文件 @
a59ad393
...
...
@@ -25,7 +25,7 @@ module Banzai
end
def
process_link_attr
(
html_attr
)
return
if
html_attr
.
blank?
||
file_reference?
(
html_attr
)
return
if
html_attr
.
blank?
||
file_reference?
(
html_attr
)
||
hierarchical_link?
(
html_attr
)
uri
=
URI
(
html_attr
.
value
)
if
uri
.
relative?
&&
uri
.
path
.
present?
...
...
@@ -40,12 +40,17 @@ module Banzai
uri
end
def
project_wiki
context
[
:project_wiki
]
end
def
file_reference?
(
html_attr
)
!
File
.
extname
(
html_attr
.
value
).
blank?
end
def
project_wiki
context
[
:project_wiki
]
# Of the form `./link`, `../link`, or similar
def
hierarchical_link?
(
html_attr
)
html_attr
.
value
[
0
]
==
'.'
end
def
project_wiki_base_path
...
...
spec/lib/banzai/filter/wiki_link_filter_spec.rb
0 → 100644
浏览文件 @
a59ad393
require
'spec_helper'
describe
Banzai
::
Filter
::
WikiLinkFilter
,
lib:
true
do
include
FilterSpecHelper
let
(
:namespace
)
{
build
(
:namespace
,
name:
"wiki_link_ns"
)
}
let
(
:project
)
{
build
(
:empty_project
,
:public
,
name:
"wiki_link_project"
,
namespace:
namespace
)
}
let
(
:user
)
{
double
}
let
(
:project_wiki
)
{
ProjectWiki
.
new
(
project
,
user
)
}
describe
"links within the wiki (relative)"
do
describe
"hierarchical links to the current directory"
do
it
"doesn't rewrite non-file links"
do
link
=
"<a href='./page'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'./page'
)
end
it
"doesn't rewrite file links"
do
link
=
"<a href='./page.md'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'./page.md'
)
end
end
describe
"hierarchical links to the parent directory"
do
it
"doesn't rewrite non-file links"
do
link
=
"<a href='../page'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'../page'
)
end
it
"doesn't rewrite file links"
do
link
=
"<a href='../page.md'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'../page.md'
)
end
end
describe
"hierarchical links to a sub-directory"
do
it
"doesn't rewrite non-file links"
do
link
=
"<a href='./subdirectory/page'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'./subdirectory/page'
)
end
it
"doesn't rewrite file links"
do
link
=
"<a href='./subdirectory/page.md'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'./subdirectory/page.md'
)
end
end
describe
"non-hierarchical links"
do
it
'rewrites non-file links to be at the scope of the wiki root'
do
link
=
"<a href='page'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
match
(
'/wiki_link_ns/wiki_link_project/wikis/page'
)
end
it
"doesn't rewrite file links"
do
link
=
"<a href='page.md'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'page.md'
)
end
end
end
describe
"links outside the wiki (absolute)"
do
it
"doesn't rewrite links"
do
link
=
"<a href='http://example.com/page'>Link to Page</a>"
filtered_link
=
filter
(
link
,
project_wiki:
project_wiki
).
children
[
0
]
expect
(
filtered_link
.
attribute
(
'href'
).
value
).
to
eq
(
'http://example.com/page'
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录