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
d71493b6
Commit
d71493b6
authored
Feb 12, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
b27ac68a
553c9f3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
3 deletions
+44
-3
app/controllers/help_controller.rb
app/controllers/help_controller.rb
+4
-3
spec/controllers/help_controller_spec.rb
spec/controllers/help_controller_spec.rb
+40
-0
No files found.
app/controllers/help_controller.rb
View file @
d71493b6
...
...
@@ -13,9 +13,10 @@ class HelpController < ApplicationController
# Remove YAML frontmatter so that it doesn't look weird
@help_index
=
File
.
read
(
Rails
.
root
.
join
(
'doc'
,
'README.md'
)).
sub
(
YAML_FRONT_MATTER_REGEXP
,
''
)
# Prefix Markdown links with `help/` unless they are external links
# See http://rubular.com/r/X3baHTbPO2
@help_index
.
gsub!
(
%r{(?<delim>
\]\(
)(?!.+://)(?!/)(?<link>[^
\)\(
]+
\)
)}
)
do
# Prefix Markdown links with `help/` unless they are external links.
# '//' not necessarily part of URL, e.g., mailto:mail@example.com
# See https://rubular.com/r/DFHZl5w8d3bpzV
@help_index
.
gsub!
(
%r{(?<delim>
\]\(
)(?!
\w
+:)(?!/)(?<link>[^
\)\(
]+
\)
)}
)
do
"
#{
$~
[
:delim
]
}#{
Gitlab
.
config
.
gitlab
.
relative_url_root
}
/help/
#{
$~
[
:link
]
}
"
end
end
...
...
spec/controllers/help_controller_spec.rb
View file @
d71493b6
...
...
@@ -37,6 +37,46 @@ describe HelpController do
expect
(
assigns
[
:help_index
]).
to
eq
'[external](https://some.external.link)'
end
end
context
'when relative url with external on same line'
do
it
'prefix it with /help/'
do
stub_readme
(
"[API](api/README.md) [external](https://some.external.link)"
)
get
:index
expect
(
assigns
[
:help_index
]).
to
eq
'[API](/help/api/README.md) [external](https://some.external.link)'
end
end
context
'when relative url with http:// in query'
do
it
'prefix it with /help/'
do
stub_readme
(
"[API](api/README.md?go=https://example.com/)"
)
get
:index
expect
(
assigns
[
:help_index
]).
to
eq
'[API](/help/api/README.md?go=https://example.com/)'
end
end
context
'when mailto URL'
do
it
'do not change it'
do
stub_readme
(
"[report bug](mailto:bugs@example.com)"
)
get
:index
expect
(
assigns
[
:help_index
]).
to
eq
'[report bug](mailto:bugs@example.com)'
end
end
context
'when protocol-relative link'
do
it
'do not change it'
do
stub_readme
(
"[protocol-relative](//example.com)"
)
get
:index
expect
(
assigns
[
:help_index
]).
to
eq
'[protocol-relative](//example.com)'
end
end
end
describe
'GET #show'
do
...
...
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