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

URL-encode param values in GET query strings #41

Conversation

nmagedman
Copy link
Contributor

Commit 00b6b67 (tag: v0.1.12) "Fix request helper for get requests to build URI based on how API expects it" attempted to solve some unclearly-indentified problem with encoding the query string in GET-based API calls. The commit leaves param values unencoded/as-is instead of URL-encoding them.

Unfortunately, that causes a regression in that param values containing spaces lead to the error "EOFError: end of file reached".

I'm not sure what regressions we will cause by reverting 00b6b67, but that implementation is clearly broken.

Commit 00b6b67 (tag: v0.1.12)
"Fix request helper for get requests to build URI based on how API expects it"
attempted to solve some unclearly-indentified problem with encoding
the query string in GET-based API calls.  The commit leaves param values
unencoded/as-is instead of URL-encoding them.

Unfortunately, that causes a regression in that param values containing
spaces lead to the error "EOFError: end of file reached".

I'm not sure what regressions we will cause by _reverting_ 00b6b67,
but _that_ implementation is clearly broken.
@nmagedman
Copy link
Contributor Author

The main difference between the two implementations is whether they URL-encode the values, however there is another difference: how they handle nil values. 00b6b67's implementation passes them to the API endpoint as an empty string: ?username= whereas URI.encode_www_form passes such params as a simple keyword without an equal sign: ?username. While that's technically correct, it probably isn't what we want. I would propose we filter them out, or at least convert to the empty string.

@nmagedman
Copy link
Contributor Author

Some tests are failing, but it seems to me that the implementation of im.rb is wrong. Im#counters (lib/rocket_chat/messages/im.rb:85) passes a username to /api/v1/im.counters, however that API endpoint does not accept a username parameter!

I don't see any mention of username in any of these:

@nmagedman nmagedman force-pushed the noach_seekingalpha_AR-2873_url-encode_get_parameters branch from 9c5ecd5 to 7abfa2f Compare November 20, 2022 15:52
lib/rocket_chat/request_helper.rb Show resolved Hide resolved
lib/rocket_chat/messages/im.rb Show resolved Hide resolved
lib/rocket_chat/request_helper.rb Show resolved Hide resolved
@abrom
Copy link
Owner

abrom commented Nov 20, 2022

Would also be great to see a new spec to test this changed behaviour in the URI encoding.. ie passing through a value containing something that should be encoded (say an &)

@abrom
Copy link
Owner

abrom commented Dec 7, 2022

hey @nmagedman just checking if you were still good to add some tests for the changed behaviour in the URI encoding.. ie passing through a value containing something that should be encoded (say an &) ?

@nmagedman nmagedman force-pushed the noach_seekingalpha_AR-2873_url-encode_get_parameters branch from 03408c0 to b4023b6 Compare December 11, 2022 11:20
@nmagedman nmagedman requested a review from abrom December 15, 2022 15:02
Copy link
Owner

@abrom abrom left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @nmagedman 👍

unreadsFrom: '2019-01-01T12:34:56.789Z',
msgs: 4,
latest: '2019-01-23T01:23:45.678Z',
userMentions: 5,
Copy link
Owner

Choose a reason for hiding this comment

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

👍 nice

@abrom abrom merged commit b88b818 into abrom:main Dec 19, 2022
@abrom
Copy link
Owner

abrom commented Dec 19, 2022

Released in v0.2.1

@nmagedman nmagedman deleted the noach_seekingalpha_AR-2873_url-encode_get_parameters branch December 26, 2022 11:17
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

2 participants