From 4ffaa9dde52e3f9176a4ba795a66d1cd1eaa0607 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 25 May 2016 11:13:59 -0700 Subject: [PATCH] Try to encode URI before parsing so spaces in paths work. Fixes #1914 --- middleman-core/features/helpers_link_to.feature | 12 +++++++++++- middleman-core/lib/middleman-core/util/paths.rb | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) 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