Skip to content

Commit

Permalink
1.6.1dev: fix enableBlame is not defined javascript error when view…
Browse files Browse the repository at this point in the history
…ing an empty file with blame view (closes #13753)

git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.6-stable@17814 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed May 28, 2024
1 parent c159589 commit be7348f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion trac/mimeview/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def render(self, context, mimetype, content, filename=None, url=None,
renderer=renderer.__class__.__name__,
err=exception_to_unicode(e)))
else:
if not result:
if result is None:
continue

if not (force_source or getattr(renderer, 'returns_source',
Expand Down
36 changes: 32 additions & 4 deletions trac/versioncontrol/web_ui/tests/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_repository(self, repos_type, repos_dir, params):
youngest_rev = 1

def get_changeset(rev):
return Mock(Changeset, repos, rev, 'message', 'author', t)
message = 'Rev %s' % rev
return Mock(Changeset, repos, rev, message, 'author', t)

def get_node(path, rev):
if 'missing' in path:
Expand All @@ -53,14 +54,22 @@ def get_node(path, rev):
if 'file' in basename:
kind = Node.FILE
entries = ()
if 'empty' in basename:
content = b''
annotations = []
else:
content = b'Contents for %s' % to_utf8(path)
annotations = [rev]
else:
kind = Node.DIRECTORY
if 'dir' in basename:
entries = ['file.txt']
else:
entries = ['dir1', 'dir2']
entries = [posixpath.join(path, entry) for entry in entries]
content = b'Contents for %s' % to_utf8(path)
content = b''
history = [(path, r, Changeset.ADD if r == rev else Changeset.EDIT)
for r in range(rev, 0, -1)]
properties = {}
if 'properties' in path:
properties['mock-1'] = 1
Expand All @@ -72,8 +81,10 @@ def get_node(path, rev):
get_properties=lambda: properties,
get_content=lambda: io.BytesIO(content),
get_content_length=lambda: len(content),
get_content_type=lambda: 'application/octet-stream',
get_last_modified=lambda: t)
get_content_type=lambda: 'text/plain',
get_last_modified=lambda: t,
get_annotations=lambda: annotations,
get_history=lambda: iter(history))
return node

def normalize_rev(rev):
Expand Down Expand Up @@ -281,6 +292,9 @@ def test_node_with_blame_view(self):
args={'annotate': 'blame'})
rv = self.process_request(req)
fragment = str(Chrome(self.env).render_fragment(req, *rv))
self.assertIn(
{'attrs': {'src': '/trac.cgi/chrome/common/js/blame.js'}},
req.chrome['scripts'])
for line in fragment.splitlines():
if ' enableBlame(' in line:
break
Expand All @@ -291,6 +305,20 @@ def test_node_with_blame_view(self):
r''', "-\u0026\u003c\u003e\"'-file");''',
line.strip())

def test_empty_node_with_blame_view(self):
self.grant_perm('anonymous', 'BROWSER_VIEW', 'FILE_VIEW')

req = MockRequest(self.env, authname='anonymous',
path_info='/browser/allow/empty-file',
args={'annotate': 'blame'})
rv = self.process_request(req)
self.assertEqual(0, rv[1]['file']['size'])
fragment = Chrome(self.env).render_fragment(req, *rv)
self.assertIn(
{'attrs': {'src': '/trac.cgi/chrome/common/js/blame.js'}},
req.chrome['scripts'])
self.assertIn('(The file is empty)', fragment)

def test_node_in_allowed_repos_with_file_view(self):
self.grant_perm('anonymous', 'BROWSER_VIEW', 'FILE_VIEW')

Expand Down

0 comments on commit be7348f

Please sign in to comment.