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

Allow unescaped equal signs in query parameter values #39

Merged
merged 5 commits into from
Mar 27, 2019

Conversation

mahmoud
Copy link
Member

@mahmoud mahmoud commented Sep 6, 2017

Specifically, allow unescaped equal signs in query parameter values. Values are terminated by ampersands (&) or the fragment (#) or the end of the URL. See #38 for more details.

This change requires changing Twisted's tests, which inherited the overzealous escaping of urllib.

@mahmoud mahmoud requested a review from glyph September 6, 2017 23:07
@codecov-io
Copy link

codecov-io commented Sep 6, 2017

Codecov Report

Merging #39 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #39      +/-   ##
==========================================
+ Coverage   98.12%   98.15%   +0.02%     
==========================================
  Files           8        8              
  Lines        1442     1462      +20     
  Branches      166      170       +4     
==========================================
+ Hits         1415     1435      +20     
  Misses         13       13              
  Partials       14       14
Impacted Files Coverage Δ
hyperlink/test/test_url.py 99.81% <100%> (ø) ⬆️
hyperlink/_url.py 96.52% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c19cf48...ff24885. Read the comment docs.

@mahmoud
Copy link
Member Author

mahmoud commented Dec 20, 2017

@markrwilliams ^

glyph
glyph previously requested changes Jan 19, 2018
Copy link
Collaborator

@glyph glyph left a comment

Choose a reason for hiding this comment

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

The requested changes here are really just:

  • Please land the Twisted test change (Twisted's tests don't need to test hyperlink this deeply, it's hyperlink's job to make this behavior correct) before resubmitting. The change itself is OK, but I don't want to leave it in a state where it could be accidentally merged until the prereqs are done :)
  • Get rid of the comment lines in the test, since it can't be both; to_text would need to acquire an option here.

@@ -532,10 +532,18 @@ def test_parseEqualSignInParamValue(self):
"""
u = URL.from_text('http://localhost/?=x=x=x')
self.assertEqual(u.get(''), ['x=x=x'])
self.assertEqual(u.to_text(), 'http://localhost/?=x%3Dx%3Dx')
# TODO: see #38
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this a TODO? Isn't #38 the bug that specifically asks this not to be done?

Copy link
Member Author

Choose a reason for hiding this comment

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

test updated. basically this was a legacy twisted test that I was worried about breaking. The TODO was more like "TODO: fix this in Twisted's test suite". Does Twisted even still have the t.p.url tests duplicated in it? If so those will have to change/come out before updating to the 19.x hyperlink release. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah doesn't look like the Twisted test suite has had the deep tests removed yet: https://github.com/twisted/twisted/blob/8292869715d9471681ffff32296bc73b946868a3/src/twisted/python/test/test_url.py#L479

Not sure why that should block a hyperlink review/release though. Whomever does the upgrade on the Twisted side (i.e., me or you, but maybe someone else) can remove the corresponding tests based on info that'll be in the hyperlink changelog.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I feel like one should feel badly about pip install of the latest version causing downstreams' tests to fail with ~no warning ;). That said, this might be what Twisted's own compatibility policy might call a "gross violation of specifications" and there's no compatible fix-forward way to handle this (i.e.: twisted is just directly testing the wrong thing); so I remove the objection unless you can think of a way to emit a warning rather than fail.

@glyph
Copy link
Collaborator

glyph commented May 24, 2018

@mahmoud Are you planning to move this along so it can land?

@glyph
Copy link
Collaborator

glyph commented Jun 26, 2018

Time for my monthly bump here :)

@mahmoud
Copy link
Member Author

mahmoud commented Jul 7, 2018

@glyph I dunno, I've started to have my doubts about this. It seems quite minor and maybe too clever. I'm not sure how to test its effects on interoperability. Have you seen any further precedent for this minor fork in handling?

@glyph glyph changed the title WIP: Make query parameter value escaping slightly more permissive WIP: Allow unescaped equal signs in query parameter values Jul 7, 2018
@glyph
Copy link
Collaborator

glyph commented Jul 7, 2018

I can't find the original citation, but I believe I had encountered a case where I built a URL with multiple =-signs in it for feeding to an API, and the API did not work with the escaped version.

Per WHATWG, browsers (tested: Safari, Chrome, Firefox) definitely will not quote = signs in this position if they're present in the address bar. So I think this is the correct thing to do, interop-wise.

@mahmoud
Copy link
Member Author

mahmoud commented Jul 7, 2018

I guess as long as web servers are ok with it, too, that's somewhat of a quorum. Kind of weird they wouldn't have a more general decoding policy; unreserved characters get encoded all the time. Speaking of time, I still don't have the time to make the Twisted change happen, but if someone wants to yank out some of those tests, I'll meet you halfway and fix merge conflicts, etc. get this mergeable again.

@glyph
Copy link
Collaborator

glyph commented Jul 7, 2018

@twisted/twisted-contributors anybody want to take a look at removing this overzealous test for library code from the Twisted suite?

@glyph
Copy link
Collaborator

glyph commented Jul 7, 2018

Erm. How does @-mentioning teams work

@glyph
Copy link
Collaborator

glyph commented Jul 7, 2018

https://blog.github.com/2012-05-09-introducing-team-mentions/ suggests that this should have worked?

@glyph
Copy link
Collaborator

glyph commented Jul 7, 2018

Kind of weird they wouldn't have a more general decoding policy; unreserved characters get encoded all the time

Oh, for sure. If the server behaves correctly, either representation should be OK. But this is exactly why hyperlink has to allow for multiple possible quoting representations ;).

@glyph
Copy link
Collaborator

glyph commented Oct 17, 2018

Bump…

@glyph
Copy link
Collaborator

glyph commented Dec 14, 2018

👉

@glyph
Copy link
Collaborator

glyph commented Jan 22, 2019

⁉️

@glyph
Copy link
Collaborator

glyph commented Mar 12, 2019

Hey @mahmoud - any thoughts on fixing this up?

@glyph
Copy link
Collaborator

glyph commented Mar 26, 2019

🎶

@mahmoud
Copy link
Member Author

mahmoud commented Mar 26, 2019

lol ok today's your lucky day, I'm puttin everything else on hold takin a look! (for however long this train ride takes :P )

@glyph
Copy link
Collaborator

glyph commented Mar 26, 2019

Hooray, the system works

@glyph glyph self-requested a review March 26, 2019 17:54
@mahmoud mahmoud changed the title WIP: Allow unescaped equal signs in query parameter values Allow unescaped equal signs in query parameter values Mar 26, 2019
Copy link
Collaborator

@glyph glyph left a comment

Choose a reason for hiding this comment

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

Unambiguously correct. Let's ship it.

We'll deal with the fallout on the Twisted side when it lands. It is at least just a minor testing hiccup and not a functional breakage.

@glyph
Copy link
Collaborator

glyph commented Mar 27, 2019

@mahmoud

Note: feel free to review, but do not merge.

I am holding off on merging myself because this comment is still in the PR description, but if your views have moved on from this perspective, please feel free to land yourself.

@mahmoud mahmoud merged commit 3c4418b into master Mar 27, 2019
@LuRsT LuRsT deleted the query_value_encoding branch March 28, 2019 09:39
twm added a commit to twisted/twisted that referenced this pull request Apr 9, 2019
Twisted should not test Hyperlink's behavior so extensively, as
discussed at python-hyper/hyperlink#39
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