Update RE used to prefix links with /help/

Update the regular expression in the help controller used to prefix relative
links on the help page with /help/. As suggested by @rymai, the look-ahead
pattern to detect external links is simplified from `[a-zA-Z0-9.+-]` to `\w`.
This commit is contained in:
Frank Sauerburger 2019-02-12 12:44:14 +01:00
parent 44d0d0e6f9
commit 752887b9a7
No known key found for this signature in database
GPG Key ID: E2713D7E40264985
1 changed files with 2 additions and 3 deletions

View File

@ -14,10 +14,9 @@ class HelpController < ApplicationController
@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.
# 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
# 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