Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
a59ad393
Commit
a59ad393
authored
May 05, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a spec for `WikiLinkFilter`
- And fix behavior for non-file hierarchical links.
parent
f2251273
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
3 deletions
+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
No files found.
lib/banzai/filter/wiki_link_filter.rb
View file @
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
View file @
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment