Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2019-04-09 13:59:37 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2019-04-09 13:59:37 +0300
commit84229cee50420df84984ec08344a1854532ccf42 (patch)
treeb1d09c16dcf4fc39705f514c6491a9cb3d6e4205 /lib/gitlab
parent351ba813dbc89d25b7fe1d457dde8297fdf59348 (diff)
Add support for URL-encoded anchors
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/docs/element.rb16
-rw-r--r--lib/gitlab/docs/link.rb2
-rw-r--r--lib/gitlab/docs/page.rb6
3 files changed, 17 insertions, 7 deletions
diff --git a/lib/gitlab/docs/element.rb b/lib/gitlab/docs/element.rb
index a78b9a01..4d58edee 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 059ebaf1..23460f88 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 8bd5e9b9..463e3f36 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)