Fix Violations of and Reenable Lint/UriEscapeUnescape - #49629
Merged
Conversation
> Identifies places where `URI.escape` can be replaced by `CGI.escape`, `URI.encode_www_form`, or `URI.encode_www_form_component` depending on your specific use case. Also this cop identifies places where `URI.unescape` can be replaced by `CGI.unescape`, `URI.decode_www_form`, or `URI.decode_www_form_component` depending on your specific use case. Most of the required changes were already applied in #48556 and #49140 (before I know this rule existed), but the linter caught a couple that my manual searches missed. - https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UriEscapeUnescape
8 tasks
Hamms
marked this pull request as ready for review
January 27, 2023 20:51
| # @return [String] a URL | ||
| def self.build_batch_url(api_endpoint, prospects) | ||
| prospects_payload_json_encoded = URI.encode({prospects: prospects}.to_json) | ||
| prospects_payload_json_encoded = URI::DEFAULT_PARSER.escape({prospects: prospects}.to_json) |
Contributor
There was a problem hiding this comment.
Would CGI.escape work here?
Contributor
Author
There was a problem hiding this comment.
I don't think so, no; CGI.escape escapes some characters which URI.encode does not:
[development] dashboard > prospects = [{foo: 'bar'}]
=> [{:foo=>"bar"}]
[development] dashboard > URI.encode({prospects: prospects}.to_json)
(irb):2: warning: URI.escape is obsolete
=> "%7B%22prospects%22:[%7B%22foo%22:%22bar%22%7D]%7D"
[development] dashboard > CGI.escape({prospects: prospects}.to_json)
=> "%7B%22prospects%22%3A%5B%7B%22foo%22%3A%22bar%22%7D%5D%7D"
[development] dashboard > URI::DEFAULT_PARSER.escape({prospects: prospects}.to_json)
=> "%7B%22prospects%22:[%7B%22foo%22:%22bar%22%7D]%7D"It's of course possible that pardot can deal with these escaped characters, but I couldn't figure out a good way to test that so I decided it was best to exactly preserve existing behavior here, even if that means the end result isn't as lightweight as it could be.
cat5inthecradle
approved these changes
Feb 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes were applied manually. Most of the required changes were already applied in #48556 and #49140 (before I know this rule existed), but the linter caught a couple that my manual searches missed. As before, I think I chose the correct replacement for each use case but can't be 100% sure.
Links
PR Checklist: