Skip to content
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

passing --filter="...." correctly escapes the spaces into "%20" and not "+" #595

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thebravoman
Copy link

PR created against 1.2.2

Running teaspoon as

bundle exec teaspoon -s default --filter="ScenePointers are attached"

When using CGI.escape the string "ScenePointers are attached" becomes "ScenePointesr+are+attached" This is then passed as a "grep=ScenePointers+are+attached" into the url

In the JS that is running the specs in the browser the value of the grep is used to filter. We move through all the specs and encode their full name with encodeURIComponent

The result is

encodeURIComponent("ScenePointers are added")
'ScenePointers%20are%20added'

This means that on the ruby side we were escaping the space " " in the urls as '+' and on the JS side we were escaping them as "%20". One of these had to change and it seems changing it on the ruby side is the right one.

There is no right way to escape. We can use 'addressable' and URI and CGI and ERB. ERB seems to be the most straightforward for this case, it also does not bring a lot of dependencies. Just one - 'cgi'.

In the same time there seems to be no method in URI or CGI or 'addressable' gem that would address this

kireto and others added 2 commits February 20, 2023 16:49
…ot "+"

Running teaspoon as

bundle exec teaspoon -s default --filter="ScenePointers are attached"

When using CGI.escape the string "ScenePointers are attached" becomes "ScenePointesr+are+attached"
This is then passed as a "grep=ScenePointers+are+attached" into the url

In the JS that is running the specs in the browser the value of the grep is used to filter.
We move through all the specs and encode their full name with encodeURIComponent

The result is

encodeURIComponent("ScenePointers are added")
'ScenePointers%20are%20added'

This means that on the ruby side we were escaping the space " " in the urls as '+' and on the
JS side we were escaping them as "%20". One of these had to change and it seems changing it on
the ruby side is the right one.

There is no right way to escape. We can use 'addressable' and URI and CGI and ERB.
ERB seems to be the most straighforward for this case, it also does not bring a lot of dependencies.
Just one - 'cgi'.

In the same time there seems to be no method in URI or CGI or 'addressable' gem that would address this
@mathieujobin
Copy link
Collaborator

Did you check why the CI isn't happy ?

@thebravoman
Copy link
Author

thebravoman commented Apr 20, 2023

I did. It was too much and I could not directly see the connection between the change and the fails.

Let me know what you think about the PR. If you think it is in the right direction I could invest some time to understand why the specs fail.

teaspoon.gemspec Outdated
s.required_ruby_version = ">= 2.5"
s.add_dependency "railties", ">= 4.2.11"
s.required_ruby_version = ">= 2.4"
s.add_dependency "railties", ">= 3.2.5"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why allowing ruby 2.4 and rails 3.2 ?

# Using ERB::Util.url_encode instead of CGI.escape as CGI.escape will convert
# the space ' ' into a '+' and not into "%20". The JS on the front end expects
# %20
parts << "grep=#{ERB::Util.url_encode(options[:filter])}" if options[:filter].present?
Copy link
Collaborator

Choose a reason for hiding this comment

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

that seems to make sense

@mathieujobin
Copy link
Collaborator

you're right failures, seems quite unrelated

please have a look at #597

and please rebase once merged

adding a test to reproduce the problem you are fixing would be great

@thebravoman
Copy link
Author

Thanks for the feedback. Now as this makes sense I will think of a spec, rebase and clean up the teaspoon.gemspec

@mathieujobin
Copy link
Collaborator

please update your branch with latest master

Getting version 1.4.0. of teaspoon
Copy link
Collaborator

@mathieujobin mathieujobin left a comment

Choose a reason for hiding this comment

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

not sure why, but existing test fails.
and I thought you had added a new test for this fix. but I am not seeing it.

Thanks for your contribution.

hopefully it helps keeping Teaspoon alive for Rails 7.x and 8.x future.

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.

None yet

3 participants