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
=== modified file 'loggerhead/controllers/revision_ui.py'
--- loggerhead/controllers/revision_ui.py 2020-07-10 09:58:50 +0000
+++ loggerhead/controllers/revision_ui.py 2021-03-29 11:19:59 +0000
@@ -32,7 +32,9 @@
3232
3333
34def dq(p):34def dq(p):
35 return urlutils.quote(urlutils.quote(p, safe=''))35 if not isinstance(p, bytes):
36 p = p.encode('UTF-8')
37 return urlutils.quote(urlutils.quote_from_bytes(p, safe=''))
3638
3739
38class RevisionUI(TemplatedBranchView):40class RevisionUI(TemplatedBranchView):
3941
=== modified file 'loggerhead/tests/test_controllers.py'
--- loggerhead/tests/test_controllers.py 2020-07-10 09:57:51 +0000
+++ loggerhead/tests/test_controllers.py 2021-03-29 11:19:59 +0000
@@ -16,6 +16,7 @@
1616
17from __future__ import absolute_import17from __future__ import absolute_import
1818
19import json
19import tarfile20import tarfile
20import tempfile21import tempfile
2122
@@ -164,6 +165,28 @@
164 revision_ui.add_template_values(values)165 revision_ui.add_template_values(values)
165 self.assertEqual(len(values['diff_chunks']), 1)166 self.assertEqual(len(values['diff_chunks']), 1)
166167
168 def test_add_template_values_with_non_ascii(self):
169 branch_app = self.make_branch_app_for_revision_ui(
170 [(u'skr\xe1', b'content\n')], [(u'skr\xe1', b'new content\n')])
171 env = {'SCRIPT_NAME': '/',
172 'PATH_INFO': '/revision/1',
173 'QUERY_STRING': 'start_revid=1',
174 'REQUEST_METHOD': 'GET',
175 'wsgi.url_scheme': 'http',
176 'SERVER_NAME': 'localhost',
177 'SERVER_PORT': '80'}
178 revision_ui = branch_app.lookup_app(env)
179 path = revision_ui.parse_args(env)
180 values = revision_ui.get_values(path, revision_ui.kwargs, {})
181 revision_ui.add_template_values(values)
182 self.assertEqual(
183 json.loads(values['link_data']),
184 {'diff-0': 'rev-1/null%253A/%252F',
185 'diff-1': 'rev-1/null%253A/skr%25C3%25A1'})
186 self.assertEqual(
187 json.loads(values['path_to_id']),
188 {'/': 'diff-0', u'skr\xe1': 'diff-1'})
189
167 def test_get_values_smoke(self):190 def test_get_values_smoke(self):
168 branch_app = self.make_branch_app_for_revision_ui(191 branch_app = self.make_branch_app_for_revision_ui(
169 [('file', b'content\n'), ('other-file', b'other\n')],192 [('file', b'content\n'), ('other-file', b'other\n')],

Subscribers

People subscribed via source and target branches