Merge lp:~cjwatson/loggerhead/revision-ui-quote-from-bytes into lp:loggerhead

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 512
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~cjwatson/loggerhead/revision-ui-quote-from-bytes
Merge into: lp:loggerhead
Diff against target: 55 lines (+26/-1)
2 files modified
loggerhead/controllers/revision_ui.py (+3/-1)
loggerhead/tests/test_controllers.py (+23/-0)
To merge this branch: bzr merge lp:~cjwatson/loggerhead/revision-ui-quote-from-bytes
Reviewer Review Type Date Requested Status
Ioana Lasc Approve
Review via email: mp+400321@code.launchpad.net

Commit message

Fix URL-quoting of non-ASCII file names in revision_ui.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/controllers/revision_ui.py'
2--- loggerhead/controllers/revision_ui.py 2020-07-10 09:58:50 +0000
3+++ loggerhead/controllers/revision_ui.py 2021-03-29 11:19:59 +0000
4@@ -32,7 +32,9 @@
5
6
7 def dq(p):
8- return urlutils.quote(urlutils.quote(p, safe=''))
9+ if not isinstance(p, bytes):
10+ p = p.encode('UTF-8')
11+ return urlutils.quote(urlutils.quote_from_bytes(p, safe=''))
12
13
14 class RevisionUI(TemplatedBranchView):
15
16=== modified file 'loggerhead/tests/test_controllers.py'
17--- loggerhead/tests/test_controllers.py 2020-07-10 09:57:51 +0000
18+++ loggerhead/tests/test_controllers.py 2021-03-29 11:19:59 +0000
19@@ -16,6 +16,7 @@
20
21 from __future__ import absolute_import
22
23+import json
24 import tarfile
25 import tempfile
26
27@@ -164,6 +165,28 @@
28 revision_ui.add_template_values(values)
29 self.assertEqual(len(values['diff_chunks']), 1)
30
31+ def test_add_template_values_with_non_ascii(self):
32+ branch_app = self.make_branch_app_for_revision_ui(
33+ [(u'skr\xe1', b'content\n')], [(u'skr\xe1', b'new content\n')])
34+ env = {'SCRIPT_NAME': '/',
35+ 'PATH_INFO': '/revision/1',
36+ 'QUERY_STRING': 'start_revid=1',
37+ 'REQUEST_METHOD': 'GET',
38+ 'wsgi.url_scheme': 'http',
39+ 'SERVER_NAME': 'localhost',
40+ 'SERVER_PORT': '80'}
41+ revision_ui = branch_app.lookup_app(env)
42+ path = revision_ui.parse_args(env)
43+ values = revision_ui.get_values(path, revision_ui.kwargs, {})
44+ revision_ui.add_template_values(values)
45+ self.assertEqual(
46+ json.loads(values['link_data']),
47+ {'diff-0': 'rev-1/null%253A/%252F',
48+ 'diff-1': 'rev-1/null%253A/skr%25C3%25A1'})
49+ self.assertEqual(
50+ json.loads(values['path_to_id']),
51+ {'/': 'diff-0', u'skr\xe1': 'diff-1'})
52+
53 def test_get_values_smoke(self):
54 branch_app = self.make_branch_app_for_revision_ui(
55 [('file', b'content\n'), ('other-file', b'other\n')],

Subscribers

People subscribed via source and target branches