Opened 3 years ago
Closed 3 years ago
#13485 closed defect (fixed)
Uncaught exception when TRAC_ENV_INDEX_TEMPLATE points to file with no extension
| Reported by: | Owned by: | Jun Omae | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.4.4 |
| Component: | rendering | Version: | 1.5.3 |
| Severity: | normal | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: |
|
||
| API Changes: | |||
| Internal Changes: | |||
Description
Hello, I have just migrated my Trac install to Trac 1.5. I had some trouble getting the project index working. The reason was that my template file was named just "template" (without extension).
The new Jinja template system does things differently depending on the file extension (it tests for "html" and a few others). However, if the file has no extension it just raises an exception:
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr:Traceback (most recent call last):
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/flup/server/fcgi_base.py", line 576, in run
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: protocolStatus, appStatus = self.server.handler(self)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/flup/server/fcgi_base.py", line 1175, in handler
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: result = self.application(environ, start_response)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/lib/python3/dist-packages/trac/web/fcgi_frontend.py", line 36, in __call__
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: return self.application(environ, start_response)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/lib/python3/dist-packages/trac/web/main.py", line 528, in dispatch_request
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: send_project_index(environ, start_response, env_parent_dir,
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/lib/python3/dist-packages/trac/web/main.py", line 846, in send_project_index
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: tmpl = jenv.get_template(template)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/environment.py", line 883, in get_template
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: return self._load_template(name, self.make_globals(globals))
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/environment.py", line 857, in _load_template
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: template = self.loader.load(self, name, globals)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/loaders.py", line 127, in load
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: code = environment.compile(source, name, filename)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/environment.py", line 629, in compile
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: source = self._generate(source, name, filename, defer_init=defer_init)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/environment.py", line 586, in _generate
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: return generate(
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/compiler.py", line 87, in generate
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: generator.visit(node)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/visitor.py", line 32, in visit
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: return f(node, *args, **kwargs)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/compiler.py", line 714, in visit_Template
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: eval_ctx = EvalContext(self.environment, self.name)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/local/lib/python3.10/dist-packages/jinja2/nodes.py", line 69, in __init__
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: self.autoescape = environment.autoescape(template_name)
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: File "/usr/lib/python3/dist-packages/trac/util/text.py", line 60, in autoescape_extensions
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr: return template and template.rsplit('.', 1)[1] in exts
2022-06-05 13:44:31: (mod_fastcgi.c.451) FastCGI-stderr:IndexError: list index out of range
I had to look at the sourcecode to understand what was going wrong. Maybe unknown extensions should default to html, or at least the exception should be caught and an error page shown in the web browser so the info is not hidden in webserver logs.
After renaming my template, things are working fine.
Attachments (0)
Change History (3)
comment:1 by , 3 years ago
| Component: | general → rendering |
|---|---|
| Milestone: | → 1.4.4 |
comment:2 by , 3 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
Another issue, the project index page sends contents as text/html or text/xml. We should enable autoescape even if the template file has no extension.
-
trac/web/main.py
def send_project_index(environ, start_response, pa 870 870 871 871 data['projects'] = projects 872 872 873 jenv = jinja2env(loader=FileSystemLoader(loadpaths) )873 jenv = jinja2env(loader=FileSystemLoader(loadpaths), autoescape=True) 874 874 jenv.globals.update(translation.functions) 875 875 tmpl = jenv.get_template(template) 876 876 output = valid_html_bytes(tmpl.render(**data).encode('utf-8'))
comment:3 by , 3 years ago
| Release Notes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |
Committed and merged in [17642-17643].



Thanks for the reporting!
trac/util/text.py
html', 'rss', 'xml')rsplit('.', 1)[1] in exts