diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-02-26 11:37:07 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-02-26 11:37:07 +0300 |
commit | fe4b674357b482b26b017aae54b273f31e6b5891 (patch) | |
tree | 4e3b66717936ea31ae89f23086e6c5bcb03c0314 | |
parent | 8598ba857a2f99c1767577f47df1d37a0d22f861 (diff) | |
parent | e60c23c066948e72a585c9842b70b683e06459d4 (diff) |
Merge branch 'fix/gb/fix-empty-anchors' into 'master'
Fix empty anchors
See merge request gitlab-com/gitlab-docs!403
-rw-r--r-- | lib/gitlab/docs/link.rb | 16 | ||||
-rw-r--r-- | spec/gitlab/docs/link_spec.rb | 6 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/gitlab/docs/link.rb b/lib/gitlab/docs/link.rb index 8509f0ca..059ebaf1 100644 --- a/lib/gitlab/docs/link.rb +++ b/lib/gitlab/docs/link.rb @@ -4,32 +4,32 @@ module Gitlab attr_reader :link, :href, :page def initialize(link, page) - @href = link + @href = link.to_s @page = page end def to_anchor? - @href.to_s.include?('#') + !anchor_name.to_s.strip.empty? end def anchor_name - raise ArgumentError unless to_anchor? + return unless @href.include?('#') - @href.to_s.partition('#').last.downcase + @href.partition('#').last.downcase end def internal_anchor? - raise ArgumentError unless to_anchor? + return false unless to_anchor? - @href.to_s.partition('#').first.empty? + @href.partition('#').first.empty? end def internal? - @href.to_s.length > 0 && !@href.include?(':') + @href.length > 0 && !@href.include?(':') end def path - @href.to_s.partition('#').first + @href.partition('#').first end def absolute_path diff --git a/spec/gitlab/docs/link_spec.rb b/spec/gitlab/docs/link_spec.rb index e8603099..1cd9790d 100644 --- a/spec/gitlab/docs/link_spec.rb +++ b/spec/gitlab/docs/link_spec.rb @@ -23,6 +23,12 @@ describe Gitlab::Docs::Link do it { is_expected.to be_to_anchor } end + + context 'when link contains an empty anchor' do + let(:href) { '../some/page.html#' } + + it { is_expected.not_to be_to_anchor } + end end describe '#internal_anchor?' do |