Merge lp:~robru/friends/quote-urls into lp:friends

Proposed by Robert Bruce Park
Status: Merged
Approved by: Ken VanDine
Approved revision: 173
Merged at revision: 173
Proposed branch: lp:~robru/friends/quote-urls
Merge into: lp:friends
Diff against target: 47 lines (+13/-1)
3 files modified
debian/changelog (+1/-0)
friends/shorteners/base.py (+4/-1)
friends/tests/test_shortener.py (+8/-0)
To merge this branch: bzr merge lp:~robru/friends/quote-urls
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot (community) continuous-integration Approve
Robert Bruce Park Approve
Review via email: mp+156100@code.launchpad.net

Commit message

Properly quote long URLs when submitting them for shortening, so that they don't break in transit.

Description of the change

Ok, so while I was refactoring the url-shortening logic for trunk-next, I realized that we weren't quoting the URLs to be shortened, which was resulting in some pretty bad breakage in certain cases. For example, if the URL contained a plus-sign (such as the one you're looking at *right now*), the URL shortener would interpret that as a space, and then the shortened URL wouldn't point at the real URL you wanted, but at s/+/ / instead, which obviously breaks the link.

So I fixed that by running the URLs through urllib.parse.quote before submitting them for shortening, and I included a test case to ensure that the strings really are percent-encoded before going out over the wire.

Please merge this in time for raring!

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:172
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~robru/friends/quote-urls/+merge/156100/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/friends-ci/13/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/friends-raring-amd64-ci/13

Click here to trigger a rebuild:
http://s-jenkins:8080/job/friends-ci/13/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks good, but needs a debian/changelog entry

review: Needs Fixing
lp:~robru/friends/quote-urls updated
173. By Robert Bruce Park

Rebase on trunk.

Revision history for this message
Robert Bruce Park (robru) wrote :

Ok, rebased with changelog, please merge ;-)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:173
http://jenkins.qa.ubuntu.com/job/friends-ci/15/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/friends-raring-amd64-ci/15

Click here to trigger a rebuild:
http://s-jenkins:8080/job/friends-ci/15/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2013-03-29 16:05:24 +0000
+++ debian/changelog 2013-03-29 16:23:20 +0000
@@ -1,6 +1,7 @@
1friends (0.1.3daily13.03.29-0ubuntu1) UNRELEASED; urgency=low1friends (0.1.3daily13.03.29-0ubuntu1) UNRELEASED; urgency=low
22
3 * Don't delete stale avatars, just redownload periodically (LP: #1153896)3 * Don't delete stale avatars, just redownload periodically (LP: #1153896)
4 * Quote URLs properly during shortening.
45
5 -- Robert Bruce Park <robert.park@canonical.com> Fri, 29 Mar 2013 08:58:45 -07006 -- Robert Bruce Park <robert.park@canonical.com> Fri, 29 Mar 2013 08:58:45 -0700
67
78
=== modified file 'friends/shorteners/base.py'
--- friends/shorteners/base.py 2013-02-13 02:05:37 +0000
+++ friends/shorteners/base.py 2013-03-29 16:23:20 +0000
@@ -20,6 +20,8 @@
20 ]20 ]
2121
2222
23from urllib.parse import quote
24
23from friends.utils.http import Downloader25from friends.utils.http import Downloader
2426
2527
@@ -29,4 +31,5 @@
29 fqdn = None31 fqdn = None
3032
31 def shorten(self, url):33 def shorten(self, url):
32 return Downloader(self.URL_TEMPLATE.format(url)).get_string().rstrip()34 return Downloader(
35 self.URL_TEMPLATE.format(quote(url, safe=''))).get_string().rstrip()
3336
=== modified file 'friends/tests/test_shortener.py'
--- friends/tests/test_shortener.py 2013-03-14 19:14:03 +0000
+++ friends/tests/test_shortener.py 2013-03-29 16:23:20 +0000
@@ -105,3 +105,11 @@
105 def test_is_not_shortened(self):105 def test_is_not_shortened(self):
106 # Test a URL that has not been shortened.106 # Test a URL that has not been shortened.
107 self.assertFalse(lookup.is_shortened('http://www.python.org/bar'))107 self.assertFalse(lookup.is_shortened('http://www.python.org/bar'))
108
109 @mock.patch('friends.shorteners.base.Downloader')
110 def test_urls_quoted_properly(self, dl_mock):
111 lookup.lookup('tinyurl.com').shorten(
112 'http://example.com/~user/stuff/+things')
113 dl_mock.assert_called_once_with(
114 'http://tinyurl.com/api-create.php?url=http%3A%2F%2Fexample.com'
115 '%2F%7Euser%2Fstuff%2F%2Bthings')

Subscribers

People subscribed via source and target branches