From 5d2c4411ca616095ddde33794299677ab6cf85aa Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Mon, 23 Apr 2018 15:16:02 +0100 Subject: [PATCH] (PDOC-36) fix hack for README urls Discovered that this hack was finding broken links and then replacing all instances of the link text in the README. This led to a lot of non-links being affected. This patch works harder to match only actual links and works as far as I can tell. --- lib/puppet-strings/yard/util.rb | 2 +- spec/unit/puppet-strings/yard/util_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/puppet-strings/yard/util.rb b/lib/puppet-strings/yard/util.rb index 29a701c29..3e505c277 100644 --- a/lib/puppet-strings/yard/util.rb +++ b/lib/puppet-strings/yard/util.rb @@ -24,7 +24,7 @@ def self.scrub_string(str) # @return [String] HTML document with links converted def self.github_to_yard_links(data) data.scan(/href\=\"\#(.+)\"/).each do |bad_link| - data.gsub!(bad_link.first, "label-#{bad_link.first.capitalize.gsub('-', '+')}") + data.gsub!("=\"##{bad_link.first}\"", "=\"#label-#{bad_link.first.capitalize.gsub('-', '+')}\"") end data end diff --git a/spec/unit/puppet-strings/yard/util_spec.rb b/spec/unit/puppet-strings/yard/util_spec.rb index 3814c2e04..6611284e6 100644 --- a/spec/unit/puppet-strings/yard/util_spec.rb +++ b/spec/unit/puppet-strings/yard/util_spec.rb @@ -39,5 +39,10 @@ str = '' expect(subject.github_to_yard_links(str)).to eq(str) end + + it 'leaves plain text alone' do + str = ' module-description' + expect(subject.github_to_yard_links(str)).to eq(' module-description') + end end end