#438 Retain url encoding when parsing specfile Source urls
Merged 2 years ago by ngompa. Opened 2 years ago by oturpe.
oturpe/FedoraReview keep-source-urls-encoded  into  master

@@ -21,7 +21,6 @@ 

  

  import re

  import sys

- from six.moves.urllib.parse import unquote

  

  import rpm

  
@@ -168,7 +167,9 @@ 

                  continue

              tag = srctype + str(num)

              try:

-                 result[tag] = self.spec.sourceHeader.format(unquote(url))

+                 # '%' has special meaning both in urls and Python format strings.

+                 escaped = url.replace("%", "%%")

+                 result[tag] = self.spec.sourceHeader.format(escaped)

              except Exception:

                  raise SpecParseReviewError("Cannot parse %s url %s" % (tag, url))

          return result

Source urls parsed from specfile are fetched during fedora-review run.
This can only work reliably if the urls are valid in the specfile
and they are kept in valid form during processing.
Thus, call to unencode when the specfile is parsed is removed.

Unencode was there due to rhbz#920376,
error when percent-encoded url was used as a Python format string.
A better solution is to escape % before calling format.

There was a period of time when unencoded, invalid urls worked,
because FancyURLopener could still process them.
Since then, it has been replaced with urllib.request.urlopen,
at which point things broke.

Resolves #435

rebased onto d4206b3

2 years ago

Pull-Request has been merged by ngompa

2 years ago
Metadata