[Yum-devel] [UG] encoding characters in URL
Chris Lumens
clumens at redhat.com
Thu Feb 3 22:35:55 UTC 2005
> Honestly, I don't think it even occurred to me to check. The one
> warning I'll give is that you need to make sure you do it in such a
> way that it doesn't screw up the other protocols. I'd probably do it
> in grabber.URLGrabber._parse_url.
That seemed really easy, which makes me wonder what I am forgetting.
Attached below is a patch to take care of the quoting and unquoting for
HTTP and HTTPS protocols only. I don't think I see any way for URLs on
other protocols to get mangled.
- Chris
diff -ruN yum-2.1.13.orig/urlgrabber/grabber.py yum-2.1.13/urlgrabber/grabber.py
--- yum-2.1.13.orig/urlgrabber/grabber.py 2005-01-20 01:59:18.000000000 -0500
+++ yum-2.1.13/urlgrabber/grabber.py 2005-02-03 17:22:12.000000000 -0500
@@ -287,6 +287,7 @@
import rfc822
import time
import string
+import urllib
import urllib2
from stat import * # S_* and ST_*
@@ -570,7 +571,10 @@
(url, parts) = self._parse_url(url)
(scheme, host, path, parm, query, frag) = parts
if filename is None:
- filename = os.path.basename( path )
+ if scheme in [ 'http', 'https' ]:
+ filename = os.path.basename( urllib.unquote(path) )
+ else:
+ filename = os.path.basename( path )
if scheme == 'file' and not opts.copy_local:
# just return the name of the local file - don't make a
# copy currently
@@ -662,6 +666,10 @@
(scheme, host, path, parm, query, frag) = \
urlparse.urlparse(url)
path = os.path.normpath(path)
+
+ if scheme in [ 'http', 'https' ]:
+ path = urllib.quote(path)
+
if '@' in host and auth_handler and scheme in ['http', 'https']:
try:
user_pass, host = host.split('@', 1)
More information about the Yum-devel
mailing list