diff --git a/lib/docs/filters/core/normalize_urls.rb b/lib/docs/filters/core/normalize_urls.rb index 3be6a12c..34b1ddeb 100644 --- a/lib/docs/filters/core/normalize_urls.rb +++ b/lib/docs/filters/core/normalize_urls.rb @@ -20,6 +20,7 @@ module Docs def normalize_url(str) str.strip! str.gsub!(' ', '%20') + str = context[:fix_urls_before_parse].call(str) if context[:fix_urls_before_parse] url = to_absolute_url(str) while new_url = fix_url(url) diff --git a/test/lib/docs/filters/core/normalize_urls_test.rb b/test/lib/docs/filters/core/normalize_urls_test.rb index f3eee919..9523ad1d 100644 --- a/test/lib/docs/filters/core/normalize_urls_test.rb +++ b/test/lib/docs/filters/core/normalize_urls_test.rb @@ -115,6 +115,24 @@ class NormalizeUrlsFilterTest < MiniTest::Spec end end + context "when context[:fix_urls_before_parse] is a block" do + before do + @body = link_to 'foo[bar]' + end + + it "calls the block with each absolute url" do + context[:fix_urls_before_parse] = ->(arg) { (@args ||= []).push(arg); nil } + @body += link_to 'foo[bar]' + filter.call + assert_equal ['foo[bar]'] * 2, @args + end + + it "replaces the url with the block's return value" do + context[:fix_urls_before_parse] = ->(url) { '/fixed' } + assert_equal link_to('http://example.com/fixed'), filter_output_string + end + end + context "when context[:fix_urls] is a block" do before do @body = link_to 'http://example.com/path?#'