Merge pull request #408 from bhollis/unicode
Support Unicode characters in filenames
This commit is contained in:
commit
00a7a1969e
9 changed files with 46 additions and 13 deletions
|
@ -13,6 +13,10 @@ require "middleman-core/vendor/hooks-0.2.0/lib/hooks"
|
|||
|
||||
require "middleman-core/sitemap"
|
||||
|
||||
# Let's serve all HTML as UTF-8
|
||||
::Rack::Mime::MIME_TYPES['.html'] = 'text/html;charset=utf8'
|
||||
::Rack::Mime::MIME_TYPES['.htm'] = 'text/html;charset=utf8'
|
||||
|
||||
# Core Middleman Class
|
||||
module Middleman
|
||||
class Application
|
||||
|
@ -381,18 +385,20 @@ module Middleman
|
|||
start_time = Time.now
|
||||
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
@original_path = env["PATH_INFO"].dup
|
||||
@escaped_path = @original_path.gsub("%20", " ")
|
||||
@request_path = full_path(@escaped_path)
|
||||
|
||||
@original_path = URI.decode(env["PATH_INFO"].dup)
|
||||
if @original_path.respond_to? :force_encoding
|
||||
@original_path.force_encoding('UTF-8')
|
||||
end
|
||||
@request_path = full_path(@original_path)
|
||||
|
||||
# Run before callbacks
|
||||
run_hook :before
|
||||
|
||||
if @escaped_path != @request_path
|
||||
if @original_path != @request_path
|
||||
# Get the resource object for this path
|
||||
resource = sitemap.find_resource_by_destination_path(@escaped_path)
|
||||
resource = sitemap.find_resource_by_destination_path(@original_path)
|
||||
end
|
||||
|
||||
|
||||
# Get the resource object for this full path
|
||||
resource ||= sitemap.find_resource_by_destination_path(@request_path)
|
||||
|
||||
|
@ -407,7 +413,7 @@ module Middleman
|
|||
|
||||
# Set a HTTP content type based on the request's extensions
|
||||
content_type resource.mime_type
|
||||
|
||||
|
||||
begin
|
||||
# Write out the contents of the page
|
||||
res.write resource.render
|
||||
|
|
|
@ -104,7 +104,8 @@ module Middleman::Cli
|
|||
output_file = File.join(build_dir, resource.destination_path)
|
||||
|
||||
begin
|
||||
response = self.class.shared_rack.get(resource.destination_path.gsub(/\s/, "%20"))
|
||||
response = self.class.shared_rack.get(URI.escape(resource.destination_path))
|
||||
|
||||
if response.status == 200
|
||||
create_file(output_file, response.body, { :force => true })
|
||||
else
|
||||
|
@ -201,7 +202,7 @@ module Middleman::Cli
|
|||
@app.sitemap.resources.select do |resource|
|
||||
resource.ext == ".css"
|
||||
end.each do |resource|
|
||||
Middleman::Cli::Build.shared_rack.get(resource.destination_path.gsub(/\s/, "%20"))
|
||||
Middleman::Cli::Build.shared_rack.get(URI.escape(resource.destination_path))
|
||||
end
|
||||
|
||||
puts "== Checking for Compass sprites" if @app.logging?
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require "rack/test"
|
||||
|
||||
Given /^a clean server$/ do
|
||||
|
@ -61,11 +63,11 @@ Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
|||
end
|
||||
|
||||
When /^I go to "([^\"]*)"$/ do |url|
|
||||
@browser.get(url)
|
||||
@browser.get(URI.escape(url))
|
||||
end
|
||||
|
||||
Then /^going to "([^\"]*)" should not raise an exception$/ do |url|
|
||||
lambda { @browser.get(url) }.should_not raise_exception
|
||||
lambda { @browser.get(URI.escape(url)) }.should_not raise_exception
|
||||
end
|
||||
|
||||
Then /^I should see "([^\"]*)"$/ do |expected|
|
||||
|
|
|
@ -29,7 +29,8 @@ module Middleman
|
|||
# @param [String] path
|
||||
# @return [String]
|
||||
def self.normalize_path(path)
|
||||
path.sub(/^\//, "").gsub("%20", " ")
|
||||
# The tr call works around a bug in Ruby's Unicode handling
|
||||
path.sub(/^\//, "").tr('','')
|
||||
end
|
||||
|
||||
# Extract the text of a Rack response as a string.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue