More URI encoding and decoding. Addresses #1406

This commit is contained in:
Thomas Reynolds 2014-11-19 10:39:48 -08:00
parent 17eb54b9dc
commit 29693e4533
7 changed files with 11 additions and 14 deletions

View file

@ -9,7 +9,6 @@ Feature: Builder
| static.html | | static.html |
| services/index.html | | services/index.html |
| stylesheets/static.css | | stylesheets/static.css |
| spaces in file.html |
| images/blank.gif | | images/blank.gif |
| images/Read me (example).txt | | images/Read me (example).txt |
| images/Child folder/regular_file(example).txt | | images/Child folder/regular_file(example).txt |
@ -27,7 +26,6 @@ Feature: Builder
And the file "static.html" should contain "Static, no code!" And the file "static.html" should contain "Static, no code!"
And the file "services/index.html" should contain "Services" And the file "services/index.html" should contain "Services"
And the file "stylesheets/static.css" should contain "body" And the file "stylesheets/static.css" should contain "body"
And the file "spaces in file.html" should contain "spaces"
Scenario: Build glob Scenario: Build glob
Given a successfully built app at "glob-app" with flags "--glob '*.css'" Given a successfully built app at "glob-app" with flags "--glob '*.css'"

View file

@ -25,8 +25,7 @@ Feature: Directory Index
And the file "a_folder/needs_index/index.html" should contain "Indexable" And the file "a_folder/needs_index/index.html" should contain "Indexable"
And the file "leave_me_alone.html" should contain "Stay away" And the file "leave_me_alone.html" should contain "Stay away"
And the file "regular/index.html" should contain "Regular" And the file "regular/index.html" should contain "Regular"
And the file "evil spaces/index.html" should contain "Spaces" And the file "evil spaces/index.html" should contain "Filled with Evil Spaces"
Scenario: Preview normal file Scenario: Preview normal file
Given the Server is running at "indexable-app" Given the Server is running at "indexable-app"
@ -35,8 +34,8 @@ Feature: Directory Index
Scenario: Preview normal file with spaces in filename Scenario: Preview normal file with spaces in filename
Given the Server is running at "indexable-app" Given the Server is running at "indexable-app"
When I go to "/evil%20spaces/" When I go to "/evil spaces/"
Then I should see "Spaces" Then I should see "Filled with Evil Spaces"
Scenario: Preview normal file subdirectory Scenario: Preview normal file subdirectory
Given the Server is running at "indexable-app" Given the Server is running at "indexable-app"

View file

@ -1 +1 @@
Spaces Filled with Evil Spaces

View file

@ -1 +1 @@
<%= "spaces" %> <%= "correctly found spaces in file data" %>

View file

@ -40,7 +40,7 @@ module Middleman
def initialize(store, path, source_file=nil) def initialize(store, path, source_file=nil)
@store = store @store = store
@app = @store.app @app = @store.app
@path = path.gsub(' ', '%20') # handle spaces in filenames @path = path
@source_file = source_file @source_file = source_file
@destination_path = @path @destination_path = @path

View file

@ -72,13 +72,13 @@ end
When /^I go to "([^\"]*)"$/ do |url| When /^I go to "([^\"]*)"$/ do |url|
in_current_dir do in_current_dir do
@browser.get(URI.escape(url)) @browser.get(URI.encode(url))
end end
end end
Then /^going to "([^\"]*)" should not raise an exception$/ do |url| Then /^going to "([^\"]*)" should not raise an exception$/ do |url|
in_current_dir do in_current_dir do
expect{ @browser.get(URI.escape(url)) }.to_not raise_exception expect{ @browser.get(URI.encode(url)) }.to_not raise_exception
end end
end end

View file

@ -68,7 +68,7 @@ module Middleman
# @return [String] # @return [String]
def normalize_path(path) def normalize_path(path)
# The tr call works around a bug in Ruby's Unicode handling # The tr call works around a bug in Ruby's Unicode handling
path.sub(%r{^/}, '').tr('', '') URI.decode(path).sub(%r{^/}, '').tr('', '')
end end
# This is a separate method from normalize_path in case we # This is a separate method from normalize_path in case we
@ -144,7 +144,7 @@ module Middleman
path_or_resource.url path_or_resource.url
else else
path_or_resource.dup path_or_resource.dup
end.gsub(' ', '%20') end
# Try to parse URL # Try to parse URL
begin begin
@ -182,7 +182,7 @@ module Middleman
end end
if resource if resource
uri.path = relative_path_from_resource(this_resource, resource_url, effective_relative) uri.path = URI.encode(relative_path_from_resource(this_resource, resource_url, effective_relative))
else else
# If they explicitly asked for relative links but we can't find a resource... # If they explicitly asked for relative links but we can't find a resource...
raise "No resource exists at #{url}" if relative raise "No resource exists at #{url}" if relative