Fix japanese characters encoding in URLs
This commit is contained in:
parent
389e3f5a8c
commit
62dba443a0
|
@ -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.
|
||||
|
|
|
@ -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],
|
||||
|
@ -53,7 +51,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -138,18 +138,16 @@ 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
|
||||
lookup_stack.push [ non_root ]
|
||||
lookup_stack.push [ non_root,
|
||||
{ try_static: try_static }]
|
||||
lookup_stack.push [ relative_dir_no_underscore.to_s,
|
||||
{ try_static: try_static }] if relative_dir_no_underscore
|
||||
lookup_stack.push [ non_root_no_underscore,
|
||||
{ try_static: try_static }]
|
||||
|
||||
lookup_stack.push [relative_dir.to_s,
|
||||
{ preferred_engine: resource.file_descriptor[:relative_path]
|
||||
.extname[1..-1].to_sym }] if relative_dir
|
||||
lookup_stack.push [non_root]
|
||||
lookup_stack.push [non_root,
|
||||
{ try_static: try_static }]
|
||||
lookup_stack.push [relative_dir_no_underscore.to_s,
|
||||
{ try_static: try_static }] if relative_dir_no_underscore
|
||||
lookup_stack.push [non_root_no_underscore,
|
||||
{ try_static: try_static }]
|
||||
|
||||
lookup_stack.each do |args|
|
||||
partial_file = ::Middleman::TemplateRenderer.resolve_template(@app, *args)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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'
|
||||
|
@ -32,9 +32,9 @@ module Middleman
|
|||
# @return [String]
|
||||
Contract String => String
|
||||
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('', '')
|
||||
end
|
||||
end
|
||||
memoize :normalize_path
|
||||
|
||||
# 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'
|
||||
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,14 +164,10 @@ module Middleman
|
|||
|
||||
# Try to parse URL
|
||||
begin
|
||||
uri = URI(url)
|
||||
rescue ::URI::InvalidURIError
|
||||
begin
|
||||
uri = URI(::URI.encode(url))
|
||||
rescue ::URI::InvalidURIError
|
||||
# Nothing we can do with it, it's not really a URI
|
||||
return url
|
||||
end
|
||||
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
|
||||
|
||||
relative = options[:relative]
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue