Fix japanese characters encoding in URLs

This commit is contained in:
Thomas Reynolds 2016-07-10 17:03:22 -07:00
parent 389e3f5a8c
commit 62dba443a0
8 changed files with 50 additions and 44 deletions

View file

@ -1,6 +1,11 @@
master
===
# 4.1.10
* Fix unicode issues in URL deeplinks.
* Add prefix option to asset_hash (#1949)
# 4.1.9
* Fix `--watcher-*` CLI flags.

View file

@ -11,9 +11,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
def initialize(app, options_hash={}, &block)
super
if options[:helpers_only]
return
end
return if options[:helpers_only]
app.rewrite_inline_urls id: :relative_assets,
url_extensions: options.exts || app.config[:asset_extensions],

View file

@ -53,8 +53,7 @@ module Middleman
def render(*)
url = ::Middleman::Util.url_for(@store.app, @request_path,
relative: false,
find_resource: true
)
find_resource: true)
if output
output.call(path, url)

View file

@ -138,7 +138,6 @@ module Middleman
relative_dir_no_underscore = current_dir + Pathname(non_root_no_underscore)
end
lookup_stack.push [relative_dir.to_s,
{ preferred_engine: resource.file_descriptor[:relative_path]
.extname[1..-1].to_sym }] if relative_dir
@ -150,7 +149,6 @@ module Middleman
lookup_stack.push [non_root_no_underscore,
{ try_static: try_static }]
lookup_stack.each do |args|
partial_file = ::Middleman::TemplateRenderer.resolve_template(@app, *args)
break if partial_file

View file

@ -47,14 +47,13 @@ module Middleman
# @return [Boolean]
Contract String => Bool
def nonbinary_mime?(mime)
case
when mime.start_with?('text/')
if mime.start_with?('text/')
true
when mime.include?('xml') && !mime.include?('officedocument')
elsif mime.include?('xml') && !mime.include?('officedocument')
true
when mime.include?('json')
elsif mime.include?('json')
true
when mime.include?('javascript')
elsif mime.include?('javascript')
true
else
false

View file

@ -94,7 +94,7 @@ module Middleman
.transpose
.map(&::Regexp.method(:union))
match = /
/
\A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?
(?<start>#{start_delims})[ ]*\r?\n
(?<frontmatter>.*?)[ ]*\r?\n?

View file

@ -1,8 +1,8 @@
# Core Pathname library used for traversal
require 'pathname'
require 'uri'
require 'memoist'
require 'addressable'
require 'memoist'
require 'tilt'
require 'middleman-core/contracts'
@ -111,7 +111,7 @@ module Middleman
raise ArgumentError, '#asset_url must be run in a context with current_resource if relative: true'
end
uri = URI(path)
uri = ::Middleman::Util.parse_uri(path)
path = uri.path
# Ensure the url we pass into find_resource_by_destination_path is not a
@ -131,9 +131,15 @@ module Middleman
end
end
final_result = ::URI.encode(relative_path_from_resource(options[:current_resource], result, options[:relative]))
final_result = ::Addressable::URI.encode(
relative_path_from_resource(
options[:current_resource],
result,
options[:relative]
)
)
result_uri = URI(final_result)
result_uri = ::Middleman::Util.parse_uri(final_result)
result_uri.query = uri.query
result_uri.fragment = uri.fragment
result_uri.to_s
@ -158,15 +164,11 @@ module Middleman
# Try to parse URL
begin
uri = URI(url)
rescue ::URI::InvalidURIError
begin
uri = URI(::URI.encode(url))
rescue ::URI::InvalidURIError
uri = ::Middleman::Util.parse_uri(url)
rescue ::Addressable::URI::InvalidURIError
# Nothing we can do with it, it's not really a URI
return url
end
end
relative = options[:relative]
raise "Can't use the relative option with an external URL" if relative && uri.host
@ -206,7 +208,13 @@ module Middleman
if resource
uri.path = if this_resource
::URI.encode(relative_path_from_resource(this_resource, resource_url, effective_relative))
::Addressable::URI.encode(
relative_path_from_resource(
this_resource,
resource_url,
effective_relative
)
)
else
resource_url
end
@ -284,16 +292,15 @@ module Middleman
# @return [Boolean] Whether the path matches the matcher
Contract PATH_MATCHER, String => Bool
def path_match(matcher, path)
case
when matcher.is_a?(String)
if matcher.is_a?(String)
if matcher.include? '*'
::File.fnmatch(matcher, path)
else
path == matcher
end
when matcher.respond_to?(:match)
elsif matcher.respond_to?(:match)
!!(path =~ matcher)
when matcher.respond_to?(:call)
elsif matcher.respond_to?(:call)
matcher.call(path)
else
::File.fnmatch(matcher.to_s, path)

View file

@ -1,5 +1,5 @@
module Middleman
# Current Version
# @return [String]
VERSION = '4.1.9'.freeze unless const_defined?(:VERSION)
VERSION = '4.1.10'.freeze unless const_defined?(:VERSION)
end