Skip to content

upgrade URI.escape to CGI.escape #221

Description

@flanker

In Ruby 3.0.0 and later versions, the escape method in the URI module has been removed, leading to the error "undefined method escape' for URI:Module" 1. To address this issue, you can switch to using CGI.escape as an alternative to URI.escape. The reason for this change is that the escape method in the URI module was deprecated and removed intentionally .

Here is how you can update your code to use CGI.escape instead of URI.escape:

require 'cgi'

uri = URI(uri + path + "?q=" + CGI.escape(term))

By replacing URI.escape with CGI.escape, you ensure compatibility with Ruby 3.0.0 and above. This change aligns with the recommendation to use CGI.escape, URI.encode_www_form, or URI.encode_www_form_component depending on your specific use case .

Using CGI.escape provides a suitable alternative for encoding URI components and ensures your code remains functional across different Ruby versions.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions