Reimplement URI.encode with URI::DEFAULT_PARSER - #49848
Merged
Merged
Conversation
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.
Contributor
|
This needs fixing and I believe it is connected to the change |
pablo-code-org
suggested changes
Jan 24, 2023
pablo-code-org
left a comment
Contributor
There was a problem hiding this comment.
Test needs to be fixed
URI.encodeURI.encode with URI::Parser.new
URI.encode with URI::Parser.newURI.encode with URI::DEFAULT_PARSER
pablo-code-org
approved these changes
Jan 26, 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.
URI.encodeis 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
Lint/UriEscapeUnescape#49629PR Checklist: