Skip to content

Reimplement URI.encode with URI::DEFAULT_PARSER - #49848

Merged
Hamms merged 3 commits into
stagingfrom
remove-unnecessary-uri-encode
Jan 27, 2023
Merged

Reimplement URI.encode with URI::DEFAULT_PARSER#49848
Hamms merged 3 commits into
stagingfrom
remove-unnecessary-uri-encode

Conversation

@Hamms

@Hamms Hamms commented Jan 18, 2023

Copy link
Copy Markdown
Contributor

URI.encode is deprecated as of Rails 2.7, so we need a replacement. Unfortunately, the reason it was deprecated is because the functionality it provides is considered harmful and the recommendation is to handle each different component of a URI individually, which isn't really an option here.

Ideally, we'd replace this with something more structured, and hopefully something which validates URL data earlier in the pipeline. Unfortunately, the way this it currently built it's meant to work with user-supplied data (https://github.com/code-dot-org/code-dot-org/blob/staging/pegasus/data/cdo-tutorials.csv) and be resilient to things which probably technically aren't valid URLs. Instead, I've replaced it with something which preserves existing behavior, broken though that behavior may be.

See discussions in the linked threads for more.

Links

Testing story

Added a few lines to an existing unit test to cover this use case.

Follow-up work

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

Added in e140346, I think we don't actually need this call. Before it was incorporated into the `curriculum_url` method, we were using it to encode the `teachers_notes` data in https://github.com/code-dot-org/code-dot-org/blob/staging/pegasus/data/cdo-tutorials.csv, which generally contains well-formed URLs. Notably, the method is already parsing the string as a uri with `URI.parse`, which I believe renders our current use redundant. Becasue `URI.encode` is deprecated as of Rails 2.7, I suggest we simply remove it.

Also added a few lines to an existing unit tests, to cover this use case.
@pablo-code-org

Copy link
Copy Markdown
Contributor

This needs fixing and I believe it is connected to the change

test_render_pegasus_documents                                   FAIL (73.76s)
--
4830 | Minitest::Assertion:         Page rendering errors:
4831 | [hourofcode.com/us/learn] Render failed:
4832 | bad URI(is not URI?): "https://www.codehs.com/hoc_guide_karel "
4833 | /drone/src/pegasus/sites.v3/hourofcode.com/public/learn/index.haml

@pablo-code-org pablo-code-org left a comment

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.

Test needs to be fixed

@Hamms Hamms changed the title Remove Unnecessary URI.encode Reimplement URI.encode with URI::Parser.new Jan 26, 2023
@Hamms Hamms changed the title Reimplement URI.encode with URI::Parser.new Reimplement URI.encode with URI::DEFAULT_PARSER Jan 26, 2023
@Hamms
Hamms requested a review from pablo-code-org January 26, 2023 21:47
@Hamms
Hamms merged commit 101221c into staging Jan 27, 2023
@Hamms
Hamms deleted the remove-unnecessary-uri-encode branch January 27, 2023 20:42
Hamms added a commit that referenced this pull request Apr 20, 2023
The former is deprecated as of Ruby 2.7 and removed in Ruby 3, but the latter is a drop-in replacement.

- #30570
- #49848
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 this pull request may close these issues.

2 participants