[Patches] Ronald Hiller: Re: [Python-bugs-list] urljoin() bug with odd no of '..' (PR#194)
Guido van Rossum
guido@python.org
Sun, 13 Feb 2000 19:23:02 -0500
------- Forwarded Message
Date: Sun, 13 Feb 2000 18:57:05 -0500
From: Ronald Hiller <ron@graburn.com>
To: DrMalte@ddd.de, Guido van Rossum <guido@CNRI.Reston.VA.US>
Subject: Re: [Python-bugs-list] urljoin() bug with odd no of '..' (PR#194)
I noticed your work with the urljoin function. I ran into the same thing.
My patch is slightly different.
- -=-=-=-=-=-=-=
I've been having some problems with the urljoin function. When I try
and join URLs that have '..' components that make the path above the
root, they aren't joined properly.
For example:
goof> python
Python 1.5.2 (#1, Oct 24 1999, 20:24:11) [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import urlparse
>>> urlparse.urljoin("http://www.xyz.com", "../x/y/z.gif")
'http://www.xyz.com/../x/y/z.gif'
>>>
# Now with the changes:
goof> python
Python 1.5.2 (#1, Oct 24 1999, 20:24:11) [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import urlparse
>>> urlparse.urljoin("http://www.xyz.com", "../x/y/z.gif")
'http://www.xyz.com/x/y/z.gif'
>>>
My patch for urlparse is included below...do they look reasonable?
Thanks,
Ron
I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims"). To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.
I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation. I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.
*** Lib/urlparse.py Thu Mar 18 10:10:44 1999
- --- urlparse.py Sun Feb 13 16:51:36 2000
***************
*** 166,171 ****
- --- 166,175 ----
i = i+1
else:
break
+ while segments[0] == '':
+ del segments[0]
+ while segments[0] == '..':
+ del segments[0]
if len(segments) == 2 and segments[1] == '..' and segments[0] == '':
segments[-1] = ''
elif len(segments) >= 2 and segments[-1] == '..':
------- End of Forwarded Message