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
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-03-29 16:05:24 +0000
3+++ debian/changelog 2013-03-29 16:23:20 +0000
4@@ -1,6 +1,7 @@
5 friends (0.1.3daily13.03.29-0ubuntu1) UNRELEASED; urgency=low
6
7 * Don't delete stale avatars, just redownload periodically (LP: #1153896)
8+ * Quote URLs properly during shortening.
9
10 -- Robert Bruce Park <robert.park@canonical.com> Fri, 29 Mar 2013 08:58:45 -0700
11
12
13=== modified file 'friends/shorteners/base.py'
14--- friends/shorteners/base.py 2013-02-13 02:05:37 +0000
15+++ friends/shorteners/base.py 2013-03-29 16:23:20 +0000
16@@ -20,6 +20,8 @@
17 ]
18
19
20+from urllib.parse import quote
21+
22 from friends.utils.http import Downloader
23
24
25@@ -29,4 +31,5 @@
26 fqdn = None
27
28 def shorten(self, url):
29- return Downloader(self.URL_TEMPLATE.format(url)).get_string().rstrip()
30+ return Downloader(
31+ self.URL_TEMPLATE.format(quote(url, safe=''))).get_string().rstrip()
32
33=== modified file 'friends/tests/test_shortener.py'
34--- friends/tests/test_shortener.py 2013-03-14 19:14:03 +0000
35+++ friends/tests/test_shortener.py 2013-03-29 16:23:20 +0000
36@@ -105,3 +105,11 @@
37 def test_is_not_shortened(self):
38 # Test a URL that has not been shortened.
39 self.assertFalse(lookup.is_shortened('http://www.python.org/bar'))
40+
41+ @mock.patch('friends.shorteners.base.Downloader')
42+ def test_urls_quoted_properly(self, dl_mock):
43+ lookup.lookup('tinyurl.com').shorten(
44+ 'http://example.com/~user/stuff/+things')
45+ dl_mock.assert_called_once_with(
46+ 'http://tinyurl.com/api-create.php?url=http%3A%2F%2Fexample.com'
47+ '%2F%7Euser%2Fstuff%2F%2Bthings')

Subscribers

People subscribed via source and target branches