Skip to content
Snippets Groups Projects
Verified Commit 63353815 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Fix URL rewritting in the Help section


Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 507abdb7
No related branches found
No related tags found
1 merge request!7875Fix URL rewritting in the Help section
Pipeline #
Loading
@@ -7,8 +7,10 @@ class HelpController < ApplicationController
Loading
@@ -7,8 +7,10 @@ class HelpController < ApplicationController
@help_index = File.read(Rails.root.join('doc', 'README.md')) @help_index = File.read(Rails.root.join('doc', 'README.md'))
   
# Prefix Markdown links with `help/` unless they are external links # Prefix Markdown links with `help/` unless they are external links
# See http://rubular.com/r/MioSrVLK3S # See http://rubular.com/r/X3baHTbPO2
@help_index.gsub!(%r{(\]\()(?!.+://)([^\)\(]+\))}, '\1/help/\2') @help_index.gsub!(%r{(?<delim>\]\()(?!.+://)(?!/)(?<link>[^\)\(]+\))}) do
"#{$~[:delim]}#{Gitlab.config.gitlab.relative_url_root}/help/#{$~[:link]}"
end
end end
   
def show def show
Loading
Loading
---
title: Don't change relative URLs to absolute URLs in the Help page
merge_request:
author:
Loading
@@ -8,26 +8,32 @@ describe HelpController do
Loading
@@ -8,26 +8,32 @@ describe HelpController do
end end
   
describe 'GET #index' do describe 'GET #index' do
context 'when url prefixed without /help/' do context 'with absolute url' do
it 'has correct url prefix' do it 'keeps the URL absolute' do
stub_readme("[API](api/README.md)") stub_readme("[API](/api/README.md)")
get :index get :index
expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
expect(assigns[:help_index]).to eq '[API](/api/README.md)'
end end
end end
   
context 'when url prefixed with help' do context 'with relative url' do
it 'will be an absolute path' do it 'prefixes it with /help/' do
stub_readme("[API](helpful_hints/README.md)") stub_readme("[API](api/README.md)")
get :index get :index
expect(assigns[:help_index]).to eq '[API](/help/helpful_hints/README.md)'
expect(assigns[:help_index]).to eq '[API](/help/api/README.md)'
end end
end end
   
context 'when url is an external link' do context 'when url is an external link' do
it 'will not be changed' do it 'does not change it' do
stub_readme("[external](https://some.external.link)") stub_readme("[external](https://some.external.link)")
get :index get :index
expect(assigns[:help_index]).to eq '[external](https://some.external.link)' expect(assigns[:help_index]).to eq '[external](https://some.external.link)'
end end
end end
Loading
Loading
Loading
@@ -12,9 +12,9 @@ describe 'Help Pages', feature: true do
Loading
@@ -12,9 +12,9 @@ describe 'Help Pages', feature: true do
end end
   
describe 'Get the main help page' do describe 'Get the main help page' do
shared_examples_for 'help page' do shared_examples_for 'help page' do |prefix: ''|
it 'prefixes links correctly' do it 'prefixes links correctly' do
expect(page).to have_selector('div.documentation-index > ul a[href="/help/api/README.md"]') expect(page).to have_selector(%(div.documentation-index > ul a[href="#{prefix}/help/api/README.md"]))
end end
end end
   
Loading
@@ -33,5 +33,14 @@ describe 'Help Pages', feature: true do
Loading
@@ -33,5 +33,14 @@ describe 'Help Pages', feature: true do
   
it_behaves_like 'help page' it_behaves_like 'help page'
end end
context 'with a relative installation' do
before do
stub_config_setting(relative_url_root: '/gitlab')
visit help_path
end
it_behaves_like 'help page', prefix: '/gitlab'
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment