From 84229cee50420df84984ec08344a1854532ccf42 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 9 Apr 2019 10:59:37 +0000 Subject: Add support for URL-encoded anchors --- lib/gitlab/docs/element.rb | 16 +++++++++++++--- lib/gitlab/docs/link.rb | 2 +- lib/gitlab/docs/page.rb | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'lib/gitlab') diff --git a/lib/gitlab/docs/element.rb b/lib/gitlab/docs/element.rb index a78b9a011..4d58edee0 100644 --- a/lib/gitlab/docs/element.rb +++ b/lib/gitlab/docs/element.rb @@ -1,3 +1,5 @@ +require 'cgi' + module Gitlab module Docs class Element @@ -15,17 +17,25 @@ module Gitlab end def href - @href ||= attribute('href') + @href ||= self.class.decode(attribute('href')) end def id - @id ||= attribute('id') + @id ||= attribute('id')&.downcase + end + + def self.decode(name) + return if name.to_s.empty? + + CGI.unescape(name) end private def attribute(name) - @attributes.find { |attr| attr.first == name }&.last + @attributes.to_a + .find { |attr| attr.first == name } + .to_a.last end end end diff --git a/lib/gitlab/docs/link.rb b/lib/gitlab/docs/link.rb index 059ebaf1e..23460f882 100644 --- a/lib/gitlab/docs/link.rb +++ b/lib/gitlab/docs/link.rb @@ -15,7 +15,7 @@ module Gitlab def anchor_name return unless @href.include?('#') - @href.partition('#').last.downcase + @href.partition('#').last end def internal_anchor? diff --git a/lib/gitlab/docs/page.rb b/lib/gitlab/docs/page.rb index 8bd5e9b98..463e3f365 100644 --- a/lib/gitlab/docs/page.rb +++ b/lib/gitlab/docs/page.rb @@ -6,8 +6,8 @@ module Gitlab def initialize(file) @file = file - @hrefs = [] - @ids = [] + @hrefs = Set.new + @ids = Set.new return unless exists? @@ -31,7 +31,7 @@ module Gitlab end def has_anchor?(name) - @ids.include?(name) + @ids.include?(Docs::Element.decode(name.downcase)) end def self.build(path) -- cgit v1.2.3