Merge lp:~cjwatson/launchpad/git-ref-browse-commits-encoding into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18759
Proposed branch: lp:~cjwatson/launchpad/git-ref-browse-commits-encoding
Merge into: lp:launchpad
Diff against target: 53 lines (+13/-5)
2 files modified
lib/lp/code/browser/gitref.py (+1/-1)
lib/lp/code/browser/tests/test_gitref.py (+12/-4)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-ref-browse-commits-encoding
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Launchpad code reviewers Pending
Review via email: mp+353654@code.launchpad.net

Commit message

Fix GitRefContextMenu.browse_commits to cope with non-ASCII ref names.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/gitref.py'
2--- lib/lp/code/browser/gitref.py 2018-03-16 21:26:08 +0000
3+++ lib/lp/code/browser/gitref.py 2018-08-23 14:59:18 +0000
4@@ -84,7 +84,7 @@
5 text = "All commits"
6 url = "%s/log/?h=%s" % (
7 self.context.repository.getCodebrowseUrl(),
8- quote_plus(self.context.name))
9+ quote_plus(self.context.name.encode("UTF-8")))
10 return Link(url, text)
11
12 def register_merge(self):
13
14=== modified file 'lib/lp/code/browser/tests/test_gitref.py'
15--- lib/lp/code/browser/tests/test_gitref.py 2018-08-23 12:34:24 +0000
16+++ lib/lp/code/browser/tests/test_gitref.py 2018-08-23 14:59:18 +0000
17@@ -252,8 +252,10 @@
18 [canonical_url(mp)],
19 [link["href"] for link in details[5].findAll("a")])
20
21- def test_all_commits_link(self):
22- [ref] = self.factory.makeGitRefs(paths=["refs/heads/branch"])
23+ def _test_all_commits_link(self, branch_name, encoded_branch_name=None):
24+ if encoded_branch_name is None:
25+ encoded_branch_name = branch_name
26+ [ref] = self.factory.makeGitRefs(paths=["refs/heads/%s" % branch_name])
27 log = self.makeCommitLog()
28 self.hosting_fixture.getLog.result = list(reversed(log))
29 self.scanRef(ref, log[-1])
30@@ -261,8 +263,8 @@
31 recent_commits_tag = soupmatchers.Tag(
32 'recent commits', 'div', attrs={'id': 'recent-commits'})
33 expected_url = (
34- 'https://git.launchpad.dev/%s/log/?h=branch' %
35- ref.repository.shortened_path)
36+ 'https://git.launchpad.dev/%s/log/?h=%s' %
37+ (ref.repository.shortened_path, encoded_branch_name))
38 self.assertThat(
39 view(),
40 soupmatchers.HTMLContains(
41@@ -272,6 +274,12 @@
42 'all commits link', 'a', text='All commits',
43 attrs={'href': expected_url}))))
44
45+ def test_all_commits_link(self):
46+ self._test_all_commits_link("branch")
47+
48+ def test_all_commits_link_non_ascii(self):
49+ self._test_all_commits_link("\N{SNOWMAN}", "%E2%98%83")
50+
51 def test_query_count_landing_candidates(self):
52 project = self.factory.makeProduct()
53 [ref] = self.factory.makeGitRefs(target=project)