Skip to content

Fix Violations of and Reenable Lint/UriEscapeUnescape - #49629

Merged
Hamms merged 4 commits into
stagingfrom
fix-Lint/UriEscapeUnescape
Feb 22, 2023
Merged

Fix Violations of and Reenable Lint/UriEscapeUnescape#49629
Hamms merged 4 commits into
stagingfrom
fix-Lint/UriEscapeUnescape

Conversation

@Hamms

@Hamms Hamms commented Jan 3, 2023

Copy link
Copy Markdown
Contributor

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.

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:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

> 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
@Hamms
Hamms marked this pull request as ready for review January 27, 2023 20:51
@Hamms
Hamms requested review from a team January 27, 2023 20:51
@Hamms
Hamms requested review from a team and removed request for a team February 9, 2023 20:50
# @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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would CGI.escape work here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Hamms
Hamms merged commit 21855cc into staging Feb 22, 2023
@Hamms
Hamms deleted the fix-Lint/UriEscapeUnescape branch February 22, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants