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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/banzai/filter/absolute_link_filter.rb')
-rw-r--r--lib/banzai/filter/absolute_link_filter.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/banzai/filter/absolute_link_filter.rb b/lib/banzai/filter/absolute_link_filter.rb
index cc7bf3ed556..7e3024c521c 100644
--- a/lib/banzai/filter/absolute_link_filter.rb
+++ b/lib/banzai/filter/absolute_link_filter.rb
@@ -6,13 +6,13 @@ module Banzai
module Filter
# HTML filter that converts relative urls into absolute ones.
class AbsoluteLinkFilter < HTML::Pipeline::Filter
- CSS = 'a.gfm'
+ CSS = 'a.gfm'
XPATH = Gitlab::Utils::Nokogiri.css_to_xpath(CSS).freeze
def call
- return doc unless context[:only_path] == false
+ return doc if skip?
- doc.xpath(XPATH).each do |el|
+ doc.xpath(self.class::XPATH).each do |el|
process_link_attr el.attribute('href')
end
@@ -21,17 +21,21 @@ module Banzai
protected
+ def skip?
+ context[:only_path] != false
+ end
+
def process_link_attr(html_attr)
return if html_attr.blank?
return if html_attr.value.start_with?('//')
uri = URI(html_attr.value)
- html_attr.value = absolute_link_attr(uri) if uri.relative?
+ html_attr.value = convert_link_href(uri) if uri.relative?
rescue URI::Error
# noop
end
- def absolute_link_attr(uri)
+ def convert_link_href(uri)
# Here we really want to expand relative path to absolute path
URI.join(Gitlab.config.gitlab.url, uri).to_s
end