From 79b3872e1ea94c4ef9c39501223c59c5ddfdf8dc Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Fri, 3 Oct 2014 16:47:34 -0700 Subject: [PATCH] Fixing URL munging when the url includes a non key=value pair in the query string. Ex: https://cns.utoronto.ca/~cks/space/blog/?atom. Thanks to @firesock for finding this. --- utils/feed_functions.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/feed_functions.py b/utils/feed_functions.py index bf2ad6648..2f8dd256e 100644 --- a/utils/feed_functions.py +++ b/utils/feed_functions.py @@ -61,9 +61,13 @@ def utf8encode(tstr): def append_query_string_to_url(url, **kwargs): url_parts = list(urlparse.urlparse(url)) query = dict(urlparse.parse_qsl(url_parts[4])) - query.update(kwargs) - url_parts[4] = urllib.urlencode(query) + if not url_parts[4] or (url_parts[4] and len(query.keys())): + # Ensure query string is preserved. + # ?atom should be preserved, so ignore + # ?feed=atom is fine + query.update(kwargs) + url_parts[4] = urllib.urlencode(query) return urlparse.urlunparse(url_parts)