files: fixed breadcrumbs tests and escape of copy path
This commit is contained in:
parent
6a2e2f0b94
commit
88f9c583e0
2 changed files with 38 additions and 12 deletions
|
|
@ -219,6 +219,7 @@ class _ToolTip(object):
|
|||
|
||||
tooltip = _ToolTip()
|
||||
|
||||
files_icon = icon = '<i class="file-breadcrumb-copy tooltip icon-clipboard clipboard-action" data-clipboard-text="{}" title="Copy the full path"></i>'
|
||||
|
||||
def files_breadcrumbs(repo_name, commit_id, file_path, at_ref=None, limit_items=False):
|
||||
if isinstance(file_path, str):
|
||||
|
|
@ -265,7 +266,7 @@ def files_breadcrumbs(repo_name, commit_id, file_path, at_ref=None, limit_items=
|
|||
url_segments = limited_url_segments
|
||||
|
||||
full_path = file_path
|
||||
icon = '<i class="file-breadcrumb-copy tooltip icon-clipboard clipboard-action" data-clipboard-text="{}" title="Copy the full path"></i>'.format(full_path)
|
||||
icon = files_icon.format(escape(full_path))
|
||||
if file_path == '':
|
||||
return root_name
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -40,27 +40,52 @@ def test_urlify_text(url, expected_url):
|
|||
|
||||
|
||||
@pytest.mark.parametrize('repo_name, commit_id, path, expected_result', [
|
||||
# Simple case 1
|
||||
('repo', 'commit', 'a/b',
|
||||
'<a href="/repo/files/commit/"><i class="icon-home"></i></a>'
|
||||
' / '
|
||||
'<a href="/repo/files/commit/a">a</a>'
|
||||
' / '
|
||||
'b'),
|
||||
|
||||
# Simple case
|
||||
('rX<X', 'cX<X', 'pX<X/aX<X/bX<X',
|
||||
'<a href="/rX%3CX/files/cX%3CX/">rX<X</a>/'
|
||||
'<a href="/rX%3CX/files/cX%3CX/pX%3CX">pX<X</a>/'
|
||||
'<a href="/rX%3CX/files/cX%3CX/pX%3CX/aX%3CX">aX<X'
|
||||
'</a>/bX<X'),
|
||||
'<a href="/rX%3CX/files/cX%3CX/"><i class="icon-home"></i></a>'
|
||||
' / '
|
||||
'<a href="/rX%3CX/files/cX%3CX/pX%3CX">pX<X</a>'
|
||||
' / '
|
||||
'<a href="/rX%3CX/files/cX%3CX/pX%3CX/aX%3CX">aX<X</a>'
|
||||
' / '
|
||||
'bX<X'),
|
||||
|
||||
# Path with only one segment
|
||||
('rX<X', 'cX<X', 'pX<X',
|
||||
'<a href="/rX%3CX/files/cX%3CX/">rX<X</a>/pX<X'),
|
||||
'<a href="/rX%3CX/files/cX%3CX/"><i class="icon-home"></i></a>'
|
||||
' / '
|
||||
'pX<X'),
|
||||
|
||||
# Empty path
|
||||
('rX<X', 'cX<X', '', 'rX<X'),
|
||||
('rX<X', 'cX<X', '',
|
||||
'<i class="icon-home"></i>'),
|
||||
|
||||
# simple quote
|
||||
('rX"X', 'cX"X', 'pX"X/aX"X/bX"X',
|
||||
'<a href="/rX%22X/files/cX%22X/">rX"X</a>/'
|
||||
'<a href="/rX%22X/files/cX%22X/pX%22X">pX"X</a>/'
|
||||
'<a href="/rX%22X/files/cX%22X/pX%22X/aX%22X">aX"X'
|
||||
'</a>/bX"X'),
|
||||
], ids=['simple', 'one_segment', 'empty_path', 'simple_quote'])
|
||||
'<a href="/rX%22X/files/cX%22X/"><i class="icon-home"></i></a>'
|
||||
' / '
|
||||
'<a href="/rX%22X/files/cX%22X/pX%22X">pX"X</a>'
|
||||
' / '
|
||||
'<a href="/rX%22X/files/cX%22X/pX%22X/aX%22X">aX"X</a>'
|
||||
' / '
|
||||
'bX"X'),
|
||||
|
||||
], ids=['simple1', 'simple2', 'one_segment', 'empty_path', 'simple_quote'])
|
||||
def test_files_breadcrumbs_xss(
|
||||
repo_name, commit_id, path, app, expected_result):
|
||||
result = helpers.files_breadcrumbs(repo_name, commit_id, path)
|
||||
# Expect it to encode all path fragments properly. This is important
|
||||
# because it returns an instance of `literal`.
|
||||
if path != '':
|
||||
expected_result = expected_result + helpers.files_icon.format(helpers.escape(path))
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue