From 63c77322d31ec2d0b1123f72a97996f26c8c8c83 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 30 Jan 2016 13:51:06 -0500 Subject: [PATCH] Handle unencoded spaces in link hrefs --- lib/docs/filters/core/normalize_urls.rb | 2 ++ test/lib/docs/filters/core/normalize_urls_test.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/docs/filters/core/normalize_urls.rb b/lib/docs/filters/core/normalize_urls.rb index 6fd77129..3be6a12c 100644 --- a/lib/docs/filters/core/normalize_urls.rb +++ b/lib/docs/filters/core/normalize_urls.rb @@ -18,6 +18,8 @@ module Docs end def normalize_url(str) + str.strip! + str.gsub!(' ', '%20') 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 6bcb678c..f3eee919 100644 --- a/test/lib/docs/filters/core/normalize_urls_test.rb +++ b/test/lib/docs/filters/core/normalize_urls_test.rb @@ -44,6 +44,11 @@ class NormalizeUrlsFilterTest < MiniTest::Spec assert_equal link_to('#'), filter_output_string end + it "repairs un-encoded spaces" do + @body = link_to 'http://example.com/#foo bar ' + assert_equal link_to('http://example.com/#foo%20bar'), filter_output_string + end + it "retains query strings" do @body = link_to'path?query' assert_equal link_to('http://example.com/dir/path?query'), filter_output_string