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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d2f83a10
Commit
d2f83a10
authored
Jan 10, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that emails contain absolute, rather than relative, links to user uploads
parent
0a51eae5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
17 deletions
+51
-17
changelogs/unreleased/41882-respect-only-path-in-relative-link-filter.yml
...eased/41882-respect-only-path-in-relative-link-filter.yml
+5
-0
lib/banzai/filter/relative_link_filter.rb
lib/banzai/filter/relative_link_filter.rb
+11
-4
spec/lib/banzai/filter/relative_link_filter_spec.rb
spec/lib/banzai/filter/relative_link_filter_spec.rb
+35
-13
No files found.
changelogs/unreleased/41882-respect-only-path-in-relative-link-filter.yml
0 → 100644
View file @
d2f83a10
---
title
:
Ensure that emails contain absolute, rather than relative, links to user uploads
merge_request
:
16364
author
:
type
:
fixed
lib/banzai/filter/relative_link_filter.rb
View file @
d2f83a10
...
@@ -50,15 +50,22 @@ module Banzai
...
@@ -50,15 +50,22 @@ module Banzai
end
end
def
process_link_to_upload_attr
(
html_attr
)
def
process_link_to_upload_attr
(
html_attr
)
uri
_parts
=
[
html_attr
.
value
]
path
_parts
=
[
html_attr
.
value
]
if
group
if
group
uri
_parts
.
unshift
(
relative_url_root
,
'groups'
,
group
.
full_path
,
'-'
)
path
_parts
.
unshift
(
relative_url_root
,
'groups'
,
group
.
full_path
,
'-'
)
elsif
project
elsif
project
uri
_parts
.
unshift
(
relative_url_root
,
project
.
full_path
)
path
_parts
.
unshift
(
relative_url_root
,
project
.
full_path
)
end
end
html_attr
.
value
=
File
.
join
(
*
uri_parts
)
path
=
File
.
join
(
*
path_parts
)
html_attr
.
value
=
if
context
[
:only_path
]
path
else
URI
.
join
(
Gitlab
.
config
.
gitlab
.
base_url
,
path
).
to_s
end
end
end
def
process_link_to_repository_attr
(
html_attr
)
def
process_link_to_repository_attr
(
html_attr
)
...
...
spec/lib/banzai/filter/relative_link_filter_spec.rb
View file @
d2f83a10
...
@@ -8,7 +8,8 @@ describe Banzai::Filter::RelativeLinkFilter do
...
@@ -8,7 +8,8 @@ describe Banzai::Filter::RelativeLinkFilter do
group:
group
,
group:
group
,
project_wiki:
project_wiki
,
project_wiki:
project_wiki
,
ref:
ref
,
ref:
ref
,
requested_path:
requested_path
requested_path:
requested_path
,
only_path:
only_path
})
})
described_class
.
call
(
doc
,
contexts
)
described_class
.
call
(
doc
,
contexts
)
...
@@ -37,6 +38,7 @@ describe Banzai::Filter::RelativeLinkFilter do
...
@@ -37,6 +38,7 @@ describe Banzai::Filter::RelativeLinkFilter do
let
(
:commit
)
{
project
.
commit
(
ref
)
}
let
(
:commit
)
{
project
.
commit
(
ref
)
}
let
(
:project_wiki
)
{
nil
}
let
(
:project_wiki
)
{
nil
}
let
(
:requested_path
)
{
'/'
}
let
(
:requested_path
)
{
'/'
}
let
(
:only_path
)
{
true
}
shared_examples
:preserve_unchanged
do
shared_examples
:preserve_unchanged
do
it
'does not modify any relative URL in anchor'
do
it
'does not modify any relative URL in anchor'
do
...
@@ -240,26 +242,35 @@ describe Banzai::Filter::RelativeLinkFilter do
...
@@ -240,26 +242,35 @@ describe Banzai::Filter::RelativeLinkFilter do
let
(
:commit
)
{
nil
}
let
(
:commit
)
{
nil
}
let
(
:ref
)
{
nil
}
let
(
:ref
)
{
nil
}
let
(
:requested_path
)
{
nil
}
let
(
:requested_path
)
{
nil
}
let
(
:upload_path
)
{
'/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
}
let
(
:relative_path
)
{
"/
#{
project
.
full_path
}#{
upload_path
}
"
}
context
'to a project upload'
do
context
'to a project upload'
do
context
'with an absolute URL'
do
let
(
:absolute_path
)
{
Gitlab
.
config
.
gitlab
.
url
+
relative_path
}
let
(
:only_path
)
{
false
}
it
'rewrites the link correctly'
do
doc
=
filter
(
link
(
upload_path
))
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
absolute_path
)
end
end
it
'rebuilds relative URL for a link'
do
it
'rebuilds relative URL for a link'
do
doc
=
filter
(
link
(
'/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
))
doc
=
filter
(
link
(
upload_path
))
expect
(
doc
.
at_css
(
'a'
)[
'href'
])
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
.
to
eq
"/
#{
project
.
full_path
}
/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
doc
=
filter
(
nested
(
link
(
'/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
)))
doc
=
filter
(
nested
(
link
(
upload_path
)))
expect
(
doc
.
at_css
(
'a'
)[
'href'
])
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
relative_path
)
.
to
eq
"/
#{
project
.
full_path
}
/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
end
end
it
'rebuilds relative URL for an image'
do
it
'rebuilds relative URL for an image'
do
doc
=
filter
(
image
(
'/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
))
doc
=
filter
(
image
(
upload_path
))
expect
(
doc
.
at_css
(
'img'
)[
'src'
])
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
(
relative_path
)
.
to
eq
"/
#{
project
.
full_path
}
/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
doc
=
filter
(
nested
(
image
(
'/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
)))
doc
=
filter
(
nested
(
image
(
upload_path
)))
expect
(
doc
.
at_css
(
'img'
)[
'src'
])
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
(
relative_path
)
.
to
eq
"/
#{
project
.
full_path
}
/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
end
end
it
'does not modify absolute URL'
do
it
'does not modify absolute URL'
do
...
@@ -288,6 +299,17 @@ describe Banzai::Filter::RelativeLinkFilter do
...
@@ -288,6 +299,17 @@ describe Banzai::Filter::RelativeLinkFilter do
let
(
:project
)
{
nil
}
let
(
:project
)
{
nil
}
let
(
:relative_path
)
{
"/groups/
#{
group
.
full_path
}
/-/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
}
let
(
:relative_path
)
{
"/groups/
#{
group
.
full_path
}
/-/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
}
context
'with an absolute URL'
do
let
(
:absolute_path
)
{
Gitlab
.
config
.
gitlab
.
url
+
relative_path
}
let
(
:only_path
)
{
false
}
it
'rewrites the link correctly'
do
doc
=
filter
(
upload_link
)
expect
(
doc
.
at_css
(
'a'
)[
'href'
]).
to
eq
(
absolute_path
)
end
end
it
'rewrites the link correctly'
do
it
'rewrites the link correctly'
do
doc
=
filter
(
upload_link
)
doc
=
filter
(
upload_link
)
...
...
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