summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQingping Hou <dave2008713@gmail.com>2016-09-11 16:29:39 -0700
committerQingping Hou <dave2008713@gmail.com>2016-09-13 23:53:40 -0700
commit5c9376f90dc977205df374c7504d477d05bc988c (patch)
tree0d17b306a5e3103f1d030bab79fc0e582d3aaca0
parent82b8cc5d66655605091b1fa089b6a3e946bd536d (diff)
downloadgitlab-ce-5c9376f90dc977205df374c7504d477d05bc988c.tar.gz
Fix URLs with anchors in wiki
-rw-r--r--CHANGELOG1
-rw-r--r--lib/banzai/filter/wiki_link_filter/rewriter.rb1
-rw-r--r--spec/lib/banzai/pipeline/wiki_pipeline_spec.rb7
3 files changed, 9 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f1e2c5060f8..b706461ce5a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -129,6 +129,7 @@ v 8.12.0 (unreleased)
- Allow bulk update merge requests from merge requests index page
- Add notification_settings API calls !5632 (mahcsig)
- Remove duplication between project builds and admin builds view !5680 (Katarzyna Kobierska Ula Budziszewska)
+ - Fix URLs with anchors in wiki !6300 (houqp)
- Deleting source project with existing fork link will close all related merge requests !6177 (Katarzyna Kobierska Ula Budziszeska)
v 8.11.6 (unreleased)
diff --git a/lib/banzai/filter/wiki_link_filter/rewriter.rb b/lib/banzai/filter/wiki_link_filter/rewriter.rb
index 2e2c8da311e..e7a1ec8457d 100644
--- a/lib/banzai/filter/wiki_link_filter/rewriter.rb
+++ b/lib/banzai/filter/wiki_link_filter/rewriter.rb
@@ -31,6 +31,7 @@ module Banzai
def apply_relative_link_rules!
if @uri.relative? && @uri.path.present?
link = ::File.join(@wiki_base_path, @uri.path)
+ link = "#{link}##{@uri.fragment}" if @uri.fragment
@uri = Addressable::URI.parse(link)
end
end
diff --git a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb
index 51c89ac4889..ac9bde6baf1 100644
--- a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb
+++ b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb
@@ -127,6 +127,13 @@ describe Banzai::Pipeline::WikiPipeline do
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page.md\"")
end
+
+ it 'rewrites links with anchor' do
+ markdown = '[Link to Header](start-page#title)'
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start-page#title\"")
+ end
end
describe "when creating root links" do