summaryrefslogtreecommitdiff
path: root/spec/controllers/help_controller_spec.rb
diff options
context:
space:
mode:
authorFrank Sauerburger <frank@sauerburger.com>2019-02-11 22:20:39 +0100
committerFrank Sauerburger <frank@sauerburger.com>2019-02-11 23:41:58 +0100
commit44d0d0e6f96dba384bbff5da8faa05db4e881dd2 (patch)
treed12df89608e3ed2916adb1845473ffec182f8a16 /spec/controllers/help_controller_spec.rb
parenta1215556ec6c5ab84862519b82cee99645dad357 (diff)
downloadgitlab-ce-44d0d0e6f96dba384bbff5da8faa05db4e881dd2.tar.gz
Fix broken links on help page
Update the help controller to correctly handle relative links on the help pages when the relative link is before an external link on the same line in the markdown file. Test cases have been implement to check for - relative links before external link on same line, - HTTPS in query part of link, - URLs without '//' and - protocol-relative links.
Diffstat (limited to 'spec/controllers/help_controller_spec.rb')
-rw-r--r--spec/controllers/help_controller_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb
index 5cb284e7e2d..dca67c18caa 100644
--- a/spec/controllers/help_controller_spec.rb
+++ b/spec/controllers/help_controller_spec.rb
@@ -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