summaryrefslogtreecommitdiff
path: root/app/controllers/help_controller.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 /app/controllers/help_controller.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 'app/controllers/help_controller.rb')
-rw-r--r--app/controllers/help_controller.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index e5a1fc9d6ff..53e023714b3 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -13,9 +13,11 @@ 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.
+ # RFC3986 allows alphanumeric, '+', '-' and '.' for URL schema;
+ # '//' not necessarily part of URL, e.g., mailto:mail@example.com
+ # See https://rubular.com/r/C5wTz0gE5r6x0f
+ @help_index.gsub!(%r{(?<delim>\]\()(?![a-zA-Z0-9.+-]+:)(?!/)(?<link>[^\)\(]+\))}) do
"#{$~[:delim]}#{Gitlab.config.gitlab.relative_url_root}/help/#{$~[:link]}"
end
end