- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rack.rb:89: warning: URI.unescape is obsolete #2312
Comments
Fixed here, but not yet released: #2303 You'll need to use the stable branch for now: https://github.com/middleman/middleman/tree/4.x Or downgrade to Ruby 2.6 for now |
Still not quite fixed in latest 4.x:
|
Yeah getting that when updating to ruby 2.7 |
* Keeping Ruby at 2.6.x for now * middleman/middleman#2312
Any news for the 2.7 switch ? |
for anybody interested I have this ugly hack to ignore these:
|
…or simply override the affected places. # TODO: keep this only until this is fixed https://github.com/middleman/middleman/issues/2312
require 'webrick'
require 'middleman-core/builder'
Middleman::Util.module_eval do
module_function
def normalize_path(path)
return path unless path.is_a?(String)
# The tr call works around a bug in Ruby's Unicode handling
WEBrick::HTTPUtils.unescape(path).sub(%r{^/}, '').tr('', '')
end
end
Middleman::Rack.class_eval do
# https://github.com/middleman/middleman/blob/master/middleman-core/lib/middleman-core/rack.rb#L90
def process_request(env, req, res)
start_time = Time.now
request_path = WEBrick::HTTPUtils.unescape(env['PATH_INFO'].dup)
if request_path.respond_to? :force_encoding
request_path.force_encoding('UTF-8')
end
request_path = ::Middleman::Util.full_path(request_path, @middleman)
full_request_path = File.join(env['SCRIPT_NAME'], request_path) # Path including rack mount
# Run before callbacks
@middleman.execute_callbacks(:before)
# Get the resource object for this path
resource = @middleman.sitemap.find_resource_by_destination_path(request_path.gsub(' ', '%20'))
# Return 404 if not in sitemap
return not_found(res, full_request_path) unless resource && !resource.ignored?
# If this path is a binary file, send it immediately
return send_file(resource, env) if resource.binary?
res['Content-Type'] = resource.content_type || 'text/plain'
begin
# Write out the contents of the page
res.write resource.render({}, rack: { request: req })
# Valid content is a 200 status
res.status = 200
rescue Middleman::TemplateRenderer::TemplateNotFound => e
res.write "Error: #{e.message}"
res.status = 500
end
# End the request
logger.debug "== Finishing Request: #{resource.destination_path} (#{(Time.now - start_time).round(2)}s)"
halt res.finish
end
end
Middleman::Builder.class_eval do
def output_resource(resource)
::Middleman::Util.instrument 'builder.output.resource', path: File.basename(resource.destination_path) do
output_file = @build_dir + resource.destination_path.gsub('%20', ' ')
begin
if resource.binary?
export_file!(output_file, resource.file_descriptor[:full_path])
else
response = @rack.get(::URI.encode_www_form_component(resource.request_path))
# If we get a response, save it to a tempfile.
if response.status == 200
export_file!(output_file, binary_encode(response.body))
else
trigger(:error, output_file, response.body)
return false
end
end
rescue => e
trigger(:error, output_file, "#{e}\n#{e.backtrace.join("\n")}")
return false
end
output_file
end
end
end
Middleman::Extensions::AssetHash.class_eval do
def manipulate_single_resource(resource)
return unless @exts.include?(resource.ext)
return if ignored_resource?(resource)
return if resource.ignored?
digest = if resource.binary?
::Digest::SHA1.file(resource.source_file).hexdigest[0..7]
else
# Render through the Rack interface so middleware and mounted apps get a shot
response = @rack_client.get(
::URI.encode_www_form_component(resource.destination_path),
'bypass_inline_url_rewriter_asset_hash' => 'true'
)
raise "#{resource.path} should be in the sitemap!" unless response.status == 200
::Digest::SHA1.hexdigest(response.body)[0..7]
end
path, basename, extension = split_path(resource.destination_path)
resource.destination_path = options.rename_proc.call(path, basename, digest, extension, options)
resource
end
end |
thanks. But I don't want to do that I'd rather wait for an actual fix than patch in all that code. |
@tdreyno, I admit I don't know the gem build process, but it looks like the fix for this issue is in master as of dead1c3, but it's not in the 4.x branch. Do you build the gems from the 4.x branch? Since it was committed to master in Dec. 2019 but not to the 4.x branch, is that why there is still an issue when using 4.3.10 and Ruby 2.7.1?
|
@b1tb4ng You're right. Backported. v4.3.11 |
Fixes `warning: URI.escape is obsolete` warnings. Similar to middleman#2312 and the fix 7c155c2
I'm still getting a bunch of these:
|
This still isn't fixed for me either. I get lots of this error with Ruby 2.7.2:
|
To avoid [this issue](middleman/middleman#2312)
This should avoid the warnings about "URI.unescape is obsolete" as per [this issue](middleman/middleman#2312)
@tdreyno Will you release 4.3.12 to include #2383 to resolve two other warnings @mandrean and @marcoms pointed out? (#2312 (comment) & #2312 (comment)) |
This is to prevent all the 'warning: URI.escape is obsolete' messages we're seeing. This is a known issue with Ruby 2.7 and older versions of Middleman: middleman/middleman#2312
Expected behavior and actual behavior
No logs on after the server is starting
== The Middleman is loading
== View your site at "http://localhost:4567", "http://127.0.0.1:4567"
== Inspect your site configuration at "http://localhost:4567/__middleman", "http://127.0.0.1:4567/__middleman"
/Users/johndoe/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/middleman-core-4.3.5/lib/middleman-core/rack.rb:89: warning: URI.unescape is obsolete
/Users/johndoe/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/middleman-core-4.3.5/lib/middleman-core/util/paths.rb:36: warning: URI.unescape is obsolete
Steps to reproduce the problem (from a clean middleman installation)
Init and serve a new project with ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
Additional information
The text was updated successfully, but these errors were encountered: