summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-11-28 09:01:08 +0000
committerRémy Coutable <remy@rymai.me>2016-11-28 09:01:08 +0000
commitbcc030240cf888da6a9f75250c7647bc9f8cffd7 (patch)
treea26a3806cbc9e7dddcccf821613428da63f33488
parent7f8bb20f8fb69cd2b6a8b9c2deb6aaddf886e0f3 (diff)
parentde0a7378eb0e08ab532a6ba80550abf9fe9db875 (diff)
downloadgitlab-ce-bcc030240cf888da6a9f75250c7647bc9f8cffd7.tar.gz
Merge branch 'fix-dead-help-link' into 'master'
Fix a broken link and avoid potential creation of future broken links on the help page. See merge request !7582
-rw-r--r--app/controllers/help_controller.rb6
-rw-r--r--spec/controllers/help_controller_spec.rb14
-rw-r--r--spec/features/help_pages_spec.rb24
3 files changed, 30 insertions, 14 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index 4b3c71874be..a10cdcce72b 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -6,9 +6,9 @@ class HelpController < ApplicationController
def index
@help_index = File.read(Rails.root.join('doc', 'README.md'))
- # Prefix Markdown links with `help/` unless they already have been
- # See http://rubular.com/r/ie2MlpdUMq
- @help_index.gsub!(/(\]\()(\/?help\/)?([^\)\(]+\))/, '\1/help/\3')
+ # Prefix Markdown links with `help/` unless they are external links
+ # See http://rubular.com/r/MioSrVLK3S
+ @help_index.gsub!(%r{(\]\()(?!.+://)([^\)\(]+\))}, '\1/help/\2')
end
def show
diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb
index 6fc6ea95e13..cffed987f6b 100644
--- a/spec/controllers/help_controller_spec.rb
+++ b/spec/controllers/help_controller_spec.rb
@@ -16,14 +16,6 @@ describe HelpController do
end
end
- context 'when url prefixed with help/' do
- it 'will be an absolute path' do
- stub_readme("[API](help/api/README.md)")
- get :index
- expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
- end
- end
-
context 'when url prefixed with help' do
it 'will be an absolute path' do
stub_readme("[API](helpful_hints/README.md)")
@@ -32,11 +24,11 @@ describe HelpController do
end
end
- context 'when url prefixed with /help/' do
+ context 'when url is an external link' do
it 'will not be changed' do
- stub_readme("[API](/help/api/README.md)")
+ stub_readme("[external](https://some.external.link)")
get :index
- expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
+ expect(assigns[:help_index]).to eq '[external](https://some.external.link)'
end
end
end
diff --git a/spec/features/help_pages_spec.rb b/spec/features/help_pages_spec.rb
index e2101b333e2..73d03837144 100644
--- a/spec/features/help_pages_spec.rb
+++ b/spec/features/help_pages_spec.rb
@@ -10,4 +10,28 @@ describe 'Help Pages', feature: true do
expect(page).to have_content("ssh-keygen -t rsa -C \"#{@user.email}\"")
end
end
+
+ describe 'Get the main help page' do
+ shared_examples_for 'help page' do
+ it 'prefixes links correctly' do
+ expect(page).to have_selector('div.documentation-index > ul a[href="/help/api/README.md"]')
+ end
+ end
+
+ context 'without a trailing slash' do
+ before do
+ visit help_path
+ end
+
+ it_behaves_like 'help page'
+ end
+
+ context 'with a trailing slash' do
+ before do
+ visit help_path + '/'
+ end
+
+ it_behaves_like 'help page'
+ end
+ end
end