diff --git a/middleman-core/features/helpers_link_to.feature b/middleman-core/features/helpers_link_to.feature
index 90b6f08a..fe8e8530 100644
--- a/middleman-core/features/helpers_link_to.feature
+++ b/middleman-core/features/helpers_link_to.feature
@@ -40,19 +40,29 @@ Feature: link_to helper
"""
absolute: <%= link_to "Needs Index", "/needs_index.html", relative: true %>
relative: <%= link_to "Relative", "needs_index.html", relative: true %>
+
+ absolute spaces: <%= link_to "Spaces Index", "/evil spaces.html", relative: true %>
+ relative spaces: <%= link_to "Spaces Relative", "evil spaces.html", relative: true %>
"""
And a file named "source/link_to/sub.html.erb" with:
"""
absolute: <%= link_to "Needs Index", "/needs_index.html", relative: true %>
relative: <%= link_to "Relative", "../needs_index.html", relative: true %>
+
+ absolute spaces: <%= link_to "Spaces Index", "/evil spaces.html", relative: true %>
+ relative spaces: <%= link_to "Spaces Relative", "../evil spaces.html", relative: true %>
"""
And the Server is running at "indexable-app"
When I go to "/link_to.html"
Then I should see 'absolute: Needs Index'
Then I should see 'relative: Relative'
+ Then I should see 'absolute spaces: Spaces Index'
+ Then I should see 'relative spaces: Spaces Relative'
When I go to "/link_to/sub.html"
Then I should see 'absolute: Needs Index'
Then I should see 'relative: Relative'
+ Then I should see 'absolute spaces: Spaces Index'
+ Then I should see 'relative spaces: Spaces Relative'
Scenario: link_to relative works with strip_index_file
Given a fixture app "indexable-app"
@@ -113,7 +123,7 @@ Feature: link_to helper
When I go to "/link_to/sub.html"
Then I should see 'absolute: Needs Index'
Then I should see 'relative: Relative'
-
+
Scenario: link_to knows about directory indexes
Given a fixture app "indexable-app"
And a file named "source/link_to.html.erb" with:
diff --git a/middleman-core/lib/middleman-core/util/paths.rb b/middleman-core/lib/middleman-core/util/paths.rb
index 799e198e..0f1d13b2 100644
--- a/middleman-core/lib/middleman-core/util/paths.rb
+++ b/middleman-core/lib/middleman-core/util/paths.rb
@@ -158,7 +158,7 @@ module Middleman
# Try to parse URL
begin
- uri = URI(url)
+ uri = URI(::URI.encode(url))
rescue ::URI::InvalidURIError
# Nothing we can do with it, it's not really a URI
return url