Make an effort to handle spaces in filenames in a way that url_for can handle.

This commit is contained in:
Ben Hollis 2013-08-15 21:12:29 -07:00
parent dcd760d4f8
commit 268538f926
4 changed files with 4 additions and 3 deletions

View file

@ -35,7 +35,7 @@ Feature: Directory Index
Scenario: Preview normal file with spaces in filename
Given the Server is running at "indexable-app"
When I go to "/evil spaces/"
When I go to "/evil%20spaces/"
Then I should see "Spaces"
Scenario: Preview normal file subdirectory

View file

@ -119,7 +119,7 @@ module Middleman::Cli
# @return [String] The full path of the file that was written
def render_to_file(resource)
build_dir = self.class.shared_instance.config[:build_dir]
output_file = File.join(build_dir, resource.destination_path)
output_file = File.join(build_dir, resource.destination_path.gsub('%20', ' '))
if resource.binary?
if !File.exists?(output_file)

View file

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

View file

@ -153,6 +153,7 @@ module Middleman
def self.url_for(app, path_or_resource, options={})
# Handle Resources and other things which define their own url method
url = path_or_resource.respond_to?(:url) ? path_or_resource.url : path_or_resource
url = url.gsub(' ', '%20')
begin
uri = URI(url)