Skip to content

Commit

Permalink
1.6.1dev: fix diff view to send bytes instance and TypeError not …
Browse files Browse the repository at this point in the history
…raises when `term` parameter is missing (closes #13794)

git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.6-stable@17859 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Oct 15, 2024
1 parent 10025a5 commit 2134384
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions trac/versioncontrol/web_ui/changeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ def process_request(self, req):
rm = RepositoryManager(self.env)

if req.is_xhr:
dirname, prefix = posixpath.split(req.args.get('term'))
dirname, prefix = posixpath.split(req.args.get('term') or '')
prefix = prefix.lower()
reponame, repos, path = rm.get_repository_by_path(dirname)
# an entry is a (isdir, name, path) tuple
Expand All @@ -1196,7 +1196,7 @@ def kind_order(entry):
for isdir, name, path in sorted(entries, key=kind_order)
if name.lower().startswith(prefix)]

content = to_json(paths)
content = to_json(paths).encode('utf-8')
req.send(content, 'application/json', 200)

# -- retrieve arguments
Expand Down
29 changes: 28 additions & 1 deletion trac/versioncontrol/web_ui/tests/changeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

from trac.core import TracError
from trac.test import EnvironmentStub, MockRequest, makeSuite
from trac.versioncontrol.web_ui.changeset import ChangesetModule
from trac.versioncontrol.web_ui.changeset import AnyDiffModule, ChangesetModule
from trac.web.api import RequestDone


class ChangesetModuleTestCase(unittest.TestCase):
Expand All @@ -30,9 +31,35 @@ def test_default_repository_not_configured(self):
self.assertRaises(TracError, self.cm.process_request, req)


class AnyDiffModuleTestCase(unittest.TestCase):

def setUp(self):
self.env = EnvironmentStub()
self.mod = AnyDiffModule(self.env)

def test_normal(self):
req = MockRequest(self.env, path_info='/diff', args={'term': '/'})
req.environ['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
self.assertTrue(self.mod.match_request(req))
self.assertRaises(RequestDone, self.mod.process_request, req)
self.assertEqual(b'[]', req.response_sent.getvalue())
self.assertEqual('application/json;charset=utf-8',
req.headers_sent.get('Content-Type'))

def test_without_term(self):
req = MockRequest(self.env, path_info='/diff')
req.environ['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
self.assertTrue(self.mod.match_request(req))
self.assertRaises(RequestDone, self.mod.process_request, req)
self.assertEqual(b'[]', req.response_sent.getvalue())
self.assertEqual('application/json;charset=utf-8',
req.headers_sent.get('Content-Type'))


def test_suite():
suite = unittest.TestSuite()
suite.addTest(makeSuite(ChangesetModuleTestCase))
suite.addTest(makeSuite(AnyDiffModuleTestCase))
return suite


Expand Down

0 comments on commit 2134384

Please sign in to comment.