8000 Added `CGI::Util.escapeURIComponent` and `unescapeURIComponent` by francois · Pull Request #8913 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added CGI::Util.escapeURIComponent and unescapeURIComponent #8913

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

francois
Copy link

In Nov 2021, CGI gained escapeURIComponent and unescapeURIComponent which were missing from the signatures.

Motivation

This Sorbet playground example fails because the CGI.escapeURIComponent signature does not exist at all: https://sorbet.run/#%23%20typed%3A%20true%0Aextend%20T%3A%3ASig%0A%0Arequire%20%22cgi%22%0ACGI.escapeURIComponent%28%22tada%26%22%29

# typed: true
extend T::Sig

require "cgi"
CGI.escapeURIComponent("tada&")
editor.rb:5: Method escapeURIComponent does not exist on T.class_of(CGI) https://srb.help/7003
     5 |CGI.escapeURIComponent("tada&")
            ^^^^^^^^^^^^^^^^^^
  Got T.class_of(CGI) originating from:
    editor.rb:5:
     5 |CGI.escapeURIComponent("tada&")
        ^^^
  Did you mean escapeElement? Use -a to autocorrect
    editor.rb:5: Replace with escapeElement
     5 |CGI.escapeURIComponent("tada&")
            ^^^^^^^^^^^^^^^^^^
    https://github.com/sorbet/sorbet/tree/master/rbi/stdlib/cgi.rbi#L1082: Defined here
    1082 |  def escapeElement(string, *elements); end
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1

Test plan

A new cgi.rb file was added to assert a minimum of type checking for only these two methods.

Most of CGI::Util is defined as taking untyped values and returning untyped values. A separate PR will be made to address that.

@francois francois requested a review from a team as a code owner May 23, 2025 14:12
@francois francois requested review from elliottt and removed request for a team May 23, 2025 14:12
@francois
Copy link
Author

I tried running bazel locally, but it failed to download some files. I made the minimum number of changes I could to make this PR as easy to merge as possible.

@francois francois force-pushed the add-missing-cgi-util-escape-uri-component branch from c786e49 to 4cf161f Compare May 23, 2025 14:35
Copy link
Collaborator
@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

This change seems reasonable, thank you!

There's a test failure due to a missing error assertion in your new test, which you can see locally by running:

./bazel test \
  //test:test_LSPTests/testdata/rbi/cgi \
  //test:test_PosTests/testdata/rbi/cgi \
  --config=dbg --test_output=errors

require 'cgi'

T.assert_type!(CGI.escapeURIComponent("'Stop!' said Fred"), String)
T.assert_type!(CGI.unescapeURIComponent("%27Stop%21%27+said%20Fred"), String)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test failure is because you're missing an error annotation for this line.

https://buildkite.com/sorbet/sorbet/builds/36003#0196fd92-37e9-466c-8874-ce6f2a166a59/143-446

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the tip on how to run Bazel for CGI only. I have a green build for testdata/../cgi on my end.

# ```
sig do
params(
string: ::T.untyped
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these really untyped?

Copy link
Author
@francois francois May 23, 2025

Choose a reason for hiding this comment

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

No they aren't, but if you look at the whole file, you'll see that everything else in this file is untyped. I wanted to make the smallest possible change that would be acceptable. I have another PR waiting in the wings with stronger type assertions, where inputs are String and return values are String as well.

I can type these two methods now, and the next PR will type the remaining methods.

Happy to do whatever will get this upstreamed!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm happy with T.untyped for now, thank you for making incremental changes!

In Nov 2021, CGI gained `escapeURIComponent` and `unescapeURIComponent` which
were missing from the signatures.
@francois francois force-pushed the add-missing-cgi-util-escape-uri-component branch from 4cf161f to 5490d61 Compare May 23, 2025 17:55
@francois francois requested review from elliottt and amomchilov May 23, 2025 18:24
@elliottt
Copy link
Collaborator

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_SMlfTnL0D8ISUq
https://go/builds/bui_SMlf4hkzjmL27b
https://go/builds/bui_SMlgeUAZMQUwYj

@elliottt
Copy link
Collaborator

I needed to make a small change to Stripe's codebase to land this change, and once that's present I'll approve and merge this PR. Thanks again!

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.

3 participants
0