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,7 +51,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_path(kind, source, options={})
|
def asset_path(kind, source, options={})
|
||||||
super(kind, source, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
|
super(kind, source, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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,18 +138,16 @@ 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)
|
||||||
|
|
|
@ -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'
|
||||||
|
@ -32,9 +32,9 @@ module Middleman
|
||||||
# @return [String]
|
# @return [String]
|
||||||
Contract String => String
|
Contract String => 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
|
||||||
::URI.decode(path).sub(%r{^/}, '').tr('', '')
|
::URI.decode(path).sub(%r{^/}, '').tr('', '')
|
||||||
end
|
end
|
||||||
memoize :normalize_path
|
memoize :normalize_path
|
||||||
|
|
||||||
# This is a separate method from normalize_path in case we
|
# This is a separate method from normalize_path in case we
|
||||||
|
@ -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,14 +164,10 @@ 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
|
# Nothing we can do with it, it's not really a URI
|
||||||
uri = URI(::URI.encode(url))
|
return url
|
||||||
rescue ::URI::InvalidURIError
|
|
||||||
# Nothing we can do with it, it's not really a URI
|
|
||||||
return url
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
relative = options[:relative]
|
relative = options[:relative]
|
||||||
|
@ -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