Fix japanese characters encoding in URLs
This commit is contained in:
parent
389e3f5a8c
commit
62dba443a0
8 changed files with 50 additions and 44 deletions
|
@ -1,6 +1,11 @@
|
||||||
master
|
master
|
||||||
===
|
===
|
||||||
|
|
||||||
|
# 4.1.10
|
||||||
|
|
||||||
|
* Fix unicode issues in URL deeplinks.
|
||||||
|
* Add prefix option to asset_hash (#1949)
|
||||||
|
|
||||||
# 4.1.9
|
# 4.1.9
|
||||||
|
|
||||||
* Fix `--watcher-*` CLI flags.
|
* Fix `--watcher-*` CLI flags.
|
||||||
|
|
|
@ -11,9 +11,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||||
def initialize(app, options_hash={}, &block)
|
def initialize(app, options_hash={}, &block)
|
||||||
super
|
super
|
||||||
|
|
||||||
if options[:helpers_only]
|
return if options[:helpers_only]
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
app.rewrite_inline_urls id: :relative_assets,
|
app.rewrite_inline_urls id: :relative_assets,
|
||||||
url_extensions: options.exts || app.config[:asset_extensions],
|
url_extensions: options.exts || app.config[:asset_extensions],
|
||||||
|
|
|
@ -53,8 +53,7 @@ module Middleman
|
||||||
def render(*)
|
def render(*)
|
||||||
url = ::Middleman::Util.url_for(@store.app, @request_path,
|
url = ::Middleman::Util.url_for(@store.app, @request_path,
|
||||||
relative: false,
|
relative: false,
|
||||||
find_resource: true
|
find_resource: true)
|
||||||
)
|
|
||||||
|
|
||||||
if output
|
if output
|
||||||
output.call(path, url)
|
output.call(path, url)
|
||||||
|
|
|
@ -138,19 +138,17 @@ module Middleman
|
||||||
relative_dir_no_underscore = current_dir + Pathname(non_root_no_underscore)
|
relative_dir_no_underscore = current_dir + Pathname(non_root_no_underscore)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
lookup_stack.push [relative_dir.to_s,
|
||||||
lookup_stack.push [ relative_dir.to_s,
|
|
||||||
{ preferred_engine: resource.file_descriptor[:relative_path]
|
{ preferred_engine: resource.file_descriptor[:relative_path]
|
||||||
.extname[1..-1].to_sym }] if relative_dir
|
.extname[1..-1].to_sym }] if relative_dir
|
||||||
lookup_stack.push [ non_root ]
|
lookup_stack.push [non_root]
|
||||||
lookup_stack.push [ non_root,
|
lookup_stack.push [non_root,
|
||||||
{ try_static: try_static }]
|
{ try_static: try_static }]
|
||||||
lookup_stack.push [ relative_dir_no_underscore.to_s,
|
lookup_stack.push [relative_dir_no_underscore.to_s,
|
||||||
{ try_static: try_static }] if relative_dir_no_underscore
|
{ try_static: try_static }] if relative_dir_no_underscore
|
||||||
lookup_stack.push [ non_root_no_underscore,
|
lookup_stack.push [non_root_no_underscore,
|
||||||
{ try_static: try_static }]
|
{ try_static: try_static }]
|
||||||
|
|
||||||
|
|
||||||
lookup_stack.each do |args|
|
lookup_stack.each do |args|
|
||||||
partial_file = ::Middleman::TemplateRenderer.resolve_template(@app, *args)
|
partial_file = ::Middleman::TemplateRenderer.resolve_template(@app, *args)
|
||||||
break if partial_file
|
break if partial_file
|
||||||
|
|
|
@ -47,14 +47,13 @@ module Middleman
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
Contract String => Bool
|
Contract String => Bool
|
||||||
def nonbinary_mime?(mime)
|
def nonbinary_mime?(mime)
|
||||||
case
|
if mime.start_with?('text/')
|
||||||
when mime.start_with?('text/')
|
|
||||||
true
|
true
|
||||||
when mime.include?('xml') && !mime.include?('officedocument')
|
elsif mime.include?('xml') && !mime.include?('officedocument')
|
||||||
true
|
true
|
||||||
when mime.include?('json')
|
elsif mime.include?('json')
|
||||||
true
|
true
|
||||||
when mime.include?('javascript')
|
elsif mime.include?('javascript')
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
|
@ -94,7 +94,7 @@ module Middleman
|
||||||
.transpose
|
.transpose
|
||||||
.map(&::Regexp.method(:union))
|
.map(&::Regexp.method(:union))
|
||||||
|
|
||||||
match = /
|
/
|
||||||
\A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?
|
\A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?
|
||||||
(?<start>#{start_delims})[ ]*\r?\n
|
(?<start>#{start_delims})[ ]*\r?\n
|
||||||
(?<frontmatter>.*?)[ ]*\r?\n?
|
(?<frontmatter>.*?)[ ]*\r?\n?
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Core Pathname library used for traversal
|
# Core Pathname library used for traversal
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require 'memoist'
|
|
||||||
require 'addressable'
|
require 'addressable'
|
||||||
|
require 'memoist'
|
||||||
require 'tilt'
|
require 'tilt'
|
||||||
|
|
||||||
require 'middleman-core/contracts'
|
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'
|
raise ArgumentError, '#asset_url must be run in a context with current_resource if relative: true'
|
||||||
end
|
end
|
||||||
|
|
||||||
uri = URI(path)
|
uri = ::Middleman::Util.parse_uri(path)
|
||||||
path = uri.path
|
path = uri.path
|
||||||
|
|
||||||
# Ensure the url we pass into find_resource_by_destination_path is not a
|
# Ensure the url we pass into find_resource_by_destination_path is not a
|
||||||
|
@ -131,9 +131,15 @@ module Middleman
|
||||||
end
|
end
|
||||||
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.query = uri.query
|
||||||
result_uri.fragment = uri.fragment
|
result_uri.fragment = uri.fragment
|
||||||
result_uri.to_s
|
result_uri.to_s
|
||||||
|
@ -158,15 +164,11 @@ module Middleman
|
||||||
|
|
||||||
# Try to parse URL
|
# Try to parse URL
|
||||||
begin
|
begin
|
||||||
uri = URI(url)
|
uri = ::Middleman::Util.parse_uri(url)
|
||||||
rescue ::URI::InvalidURIError
|
rescue ::Addressable::URI::InvalidURIError
|
||||||
begin
|
|
||||||
uri = URI(::URI.encode(url))
|
|
||||||
rescue ::URI::InvalidURIError
|
|
||||||
# Nothing we can do with it, it's not really a URI
|
# Nothing we can do with it, it's not really a URI
|
||||||
return url
|
return url
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
relative = options[:relative]
|
relative = options[:relative]
|
||||||
raise "Can't use the relative option with an external URL" if relative && uri.host
|
raise "Can't use the relative option with an external URL" if relative && uri.host
|
||||||
|
@ -206,7 +208,13 @@ module Middleman
|
||||||
|
|
||||||
if resource
|
if resource
|
||||||
uri.path = if this_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
|
else
|
||||||
resource_url
|
resource_url
|
||||||
end
|
end
|
||||||
|
@ -284,16 +292,15 @@ module Middleman
|
||||||
# @return [Boolean] Whether the path matches the matcher
|
# @return [Boolean] Whether the path matches the matcher
|
||||||
Contract PATH_MATCHER, String => Bool
|
Contract PATH_MATCHER, String => Bool
|
||||||
def path_match(matcher, path)
|
def path_match(matcher, path)
|
||||||
case
|
if matcher.is_a?(String)
|
||||||
when matcher.is_a?(String)
|
|
||||||
if matcher.include? '*'
|
if matcher.include? '*'
|
||||||
::File.fnmatch(matcher, path)
|
::File.fnmatch(matcher, path)
|
||||||
else
|
else
|
||||||
path == matcher
|
path == matcher
|
||||||
end
|
end
|
||||||
when matcher.respond_to?(:match)
|
elsif matcher.respond_to?(:match)
|
||||||
!!(path =~ matcher)
|
!!(path =~ matcher)
|
||||||
when matcher.respond_to?(:call)
|
elsif matcher.respond_to?(:call)
|
||||||
matcher.call(path)
|
matcher.call(path)
|
||||||
else
|
else
|
||||||
::File.fnmatch(matcher.to_s, path)
|
::File.fnmatch(matcher.to_s, path)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
# Current Version
|
# Current Version
|
||||||
# @return [String]
|
# @return [String]
|
||||||
VERSION = '4.1.9'.freeze unless const_defined?(:VERSION)
|
VERSION = '4.1.10'.freeze unless const_defined?(:VERSION)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue