Skip to content
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

Closed
lraboteau opened this issue Feb 6, 2020 · 12 comments
Closed

rack.rb:89: warning: URI.unescape is obsolete #2312

lraboteau opened this issue Feb 6, 2020 · 12 comments

Comments

@lraboteau
Copy link

lraboteau commented Feb 6, 2020

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

  • Ruby version: 2.7.0p0
  • Middleman version: 4.2
  • OS version: Mac OS 10.15.3
@tdreyno
Copy link
Member

tdreyno commented Feb 7, 2020

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

@jacobat
Copy link

jacobat commented Mar 25, 2020

Still not quite fixed in latest 4.x:

/.../ruby/2.7.0/bundler/gems/middleman-e8cf86f3e335/middleman-core/lib/middleman-core/util/paths.rb:36: warning: URI.unescape is obsolete

@alexandru-calinoiu
Copy link

Yeah getting that when updating to ruby 2.7

bmedici added a commit to bmedici/bmedici.github.io that referenced this issue Jun 18, 2020
speedy1812 added a commit to speedy1812/daysinukraine.com that referenced this issue Jul 17, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
MylesBorins Myles Borins
  * Keeping Ruby at 2.6.x for now
  * middleman/middleman#2312
@noraj
Copy link

noraj commented Aug 10, 2020

Any news for the 2.7 switch ?

@jubishop
Copy link

jubishop commented Sep 2, 2020

for anybody interested I have this ugly hack to ignore these:

bundle exec middleman build &> output.txt; cat output.txt | grep -v URI; rm output.txt

@alexanderadam
Copy link

alexanderadam commented Sep 3, 2020

for anybody interested I have this ugly hack to ignore these

…or simply override the affected places.
You can put the following in a file and require it in your config.rb:

# 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

@jubishop
Copy link

jubishop commented Sep 7, 2020

thanks. But I don't want to do that I'd rather wait for an actual fix than patch in all that code.

@b1tb4ng
Copy link

b1tb4ng commented Sep 15, 2020

@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?

/Users/bb/.gem/ruby/2.7.1/gems/middleman-core-4.3.10/lib/middleman-core/util/paths.rb:36: warning: URI.unescape is obsolete
# gem info middleman-core

*** LOCAL GEMS ***

middleman-core (4.3.10)
    Authors: Thomas Reynolds, Ben Hollis, Karl Freeman
    Homepage: http://middlemanapp.com
    License: MIT
    Installed at: /Users/bb/.gem/ruby/2.7.1

    Hand-crafted frontend development

tdreyno added a commit that referenced this issue Sep 15, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
danielleadams Danielle Adams
@tdreyno
Copy link
Member

tdreyno commented Sep 15, 2020

@b1tb4ng You're right. Backported. v4.3.11

@tdreyno tdreyno closed this as completed Sep 15, 2020
dentarg added a commit to dentarg/middleman that referenced this issue Sep 22, 2020
Fixes `warning: URI.escape is obsolete` warnings.

Similar to middleman#2312 and the fix 7c155c2
tdreyno pushed a commit that referenced this issue Sep 22, 2020
Fixes `warning: URI.escape is obsolete` warnings.

Similar to #2312 and the fix 7c155c2
@mandrean
Copy link

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin18]
$ middleman version
Middleman 4.3.11
$ bundle version
Bundler version 2.1.4 (2020-01-05 commit 32a4159325)

I'm still getting a bunch of these:

~/.rvm/gems/ruby-2.7.2/gems/middleman-core-4.3.11/lib/middleman-core/builder.rb:232: warning: URI.escape is obsolete

@marcoms
Copy link

marcoms commented Dec 2, 2020

This still isn't fixed for me either. I get lots of this error with Ruby 2.7.2:

<homedir>/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/middleman-core-4.3.11/lib/middleman-core/extensions/asset_hash.rb:90: warning: URI.escape is obsolete

ikuwow added a commit to ikuwow/query_ok that referenced this issue Dec 21, 2020
ikuwow added a commit to ikuwow/query_ok that referenced this issue Dec 21, 2020
digitalronin added a commit to ministryofjustice/test-doc-site that referenced this issue Jan 19, 2021
digitalronin added a commit to ministryofjustice/tech-docs-github-pages-publisher that referenced this issue Jan 19, 2021
This should avoid the warnings about 
"URI.unescape is obsolete" as per [this issue](middleman/middleman#2312)
@tnir
Copy link
Contributor

tnir commented Feb 12, 2021

@tdreyno Will you release 4.3.12 to include #2383 to resolve two other warnings @mandrean and @marcoms pointed out? (#2312 (comment) & #2312 (comment))

nahteb added a commit to alphagov/data-standards-authority that referenced this issue Oct 5, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.