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

upgrade URI.escape to CGI.escape #221

Open
flanker opened this issue May 14, 2024 · 0 comments
Open

upgrade URI.escape to CGI.escape #221

flanker opened this issue May 14, 2024 · 0 comments

Comments

@flanker
Copy link

flanker commented May 14, 2024

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.

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

No branches or pull requests

1 participant