From 101913aa2d7453cdd3da6c6a07aa37bc764f0a86 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 1 Feb 2012 20:06:18 +0100 Subject: [PATCH 1/2] Fix for creating short URLs. Certain URLs containing a lot of query string items and hash fragments (yes, I'm looking at you Google) could not be converted to short URLs properly due to URL encoding issues. Signed-off-by: Yorick Peterse --- plugins/urls.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/urls.py b/plugins/urls.py index c2eb2dc..3eda9dc 100644 --- a/plugins/urls.py +++ b/plugins/urls.py @@ -1,12 +1,13 @@ import re +import urllib from util import hook, urlnorm, http ignore = ['buttbot'] -is_gd = 'http://is.gd/create.php?format=simple&url=%s' @hook.regex(r'([a-zA-Z]+://|www\.)[^ ]+') def show_title(match, nick='', chan='', say=None): - url = urlnorm.normalize(match.group().encode('utf-8')) + matched = match.group().encode('utf-8') + url = urlnorm.normalize(matched) if not url in ignore and not nick in ignore: page, response = http.get_html_and_response(url) @@ -30,8 +31,10 @@ def show_title(match, nick='', chan='', say=None): message = 'URL title: %s' % (''.join(titleList)) if len(url) >= 80: - # Get the short URL. - short_url = http.get(is_gd % (url)) + short_url = http.get( + 'http://is.gd/create.php', + query_params = {'format': 'simple', 'url': matched} + ) # Cheap error checking if 'error: please' not in short_url.lower(): From f2c2e079c5626414dce094b352770d4b23457de8 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 1 Feb 2012 20:09:06 +0100 Subject: [PATCH 2/2] urllib is no longer needed. Signed-off-by: Yorick Peterse --- plugins/urls.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/urls.py b/plugins/urls.py index 3eda9dc..da935bf 100644 --- a/plugins/urls.py +++ b/plugins/urls.py @@ -1,5 +1,4 @@ import re -import urllib from util import hook, urlnorm, http ignore = ['buttbot']