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

Setuptools fails to parse a package url with query parameters properly #1366

Closed
jendabenda opened this issue May 16, 2018 · 2 comments
Closed

Comments

@jendabenda
Copy link

@jendabenda jendabenda commented May 16, 2018

Setuptools fails to parse a package url with query parameters properly

Case

private pip server, package_name, list of package versions on url as html page at
https://private-pip.example.com/simple/package_name/

on the page there is a link in html which points to a package file to download
<a href="https://download-server.example.com/package_name/package_name-0.1.2.tar.gz?tokena=A&amp;tokenb=B">package_name-0.1.2.tar.gz</a>

Problem

href attribute
https://../package_name-0.1.2.tar.gz?tokena=A&amp;tokenb=B">package_name-0.1.2.tar.gz
gets parased as
https://.../package_name-0.1.2.tar.gz?tokena=Aamptokenb=B">package_name-0.1.2.tar.gz
instead of
https://.../package_name-0.1.2.tar.gz?tokena=A&tokenb=B">package_name-0.1.2.tar.gz

note &amp; => amp instead of &

Solution

href decoding in function htmldecode
regexp called entity_sub is wrong

# This pattern matches a character entity reference (a decimal numeric

instead of

entity_sub = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?').sub

should be

entity_sub = re.compile(r'(&#(\d+|x[\da-fA-F]+)|[\w.:-]+;?)').sub

note rounded brackets inside regular expression

jaraco added a commit that referenced this issue Jun 5, 2018
@jaraco
Copy link
Member

@jaraco jaraco commented Jun 5, 2018

Thanks for the report. In addition to your patch, I created a test to validate the patch, but was unsuccessful. See the linked branch.

@jendabenda
Copy link
Author

@jendabenda jendabenda commented Jun 5, 2018

ok, my bad it worked only in certain cases

this simple patch will do the job (no need to modify entity_sub)

@@ -933,7 +933,7 @@ entity_sub = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?').sub
 
 
 def decode_entity(match):
-    what = match.group(1)
+    what = match.group(0)
     return unescape(what)
@jaraco jaraco closed this in 95880b3 Jun 6, 2018
jaraco added a commit that referenced this issue Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants