Bug #855
templateparser crashen on missing index in eval replacement
Description
The following input and template trigger an error and a reset connection,
template:
{{ if isinstance([field], [fieldtypes:decimal] }} test {{ endif }}
with a call to the templateparser of:
self.parser.Parse('template', field=10, fieldtypes={'X':'Y'})
I would expect the keyerror in the eval to trigger a keyerror in the uweb stack, and return at least a debug page.
The log says:
Traceback (most recent call last): File "/home/janklopper/uweb/__init__.py", line 125, in RequestHandler response = getattr(pages, method)(*args) File "/home/janklopper/uweb/pagemaker/admin.py", line 61, in _Admin fieldtypes=FIELDTYPES)) File "/home/janklopper/uweb/templateparser.py", line 324, in Parse return SafeString(''.join(tag.Parse(**kwds) for tag in self)) File "/home/janklopper/uweb/templateparser.py", line 324, in <genexpr> return SafeString(''.join(tag.Parse(**kwds) for tag in self)) File "/home/janklopper/uweb/templateparser.py", line 554, in Parse output.append(''.join(tag.Parse(**replacements) for tag in self)) File "/home/janklopper/uweb/templateparser.py", line 554, in <genexpr> output.append(''.join(tag.Parse(**replacements) for tag in self)) File "/home/janklopper/uweb/templateparser.py", line 493, in Parse if self.Expression(expr, **kwds): File "/home/janklopper/uweb/templateparser.py", line 474, in Expression return eval(''.join(nodes), None, local_vars) File "<string>", line 1, in <module> File "/home/janklopper/uweb/templateparser.py", line 59, in __getitem__ return self._tags[key].GetValue(self._values) File "/home/janklopper/uweb/templateparser.py", line 627, in GetValue value = self._GetIndex(value, index) File "/home/janklopper/uweb/templateparser.py", line 716, in _GetIndex raise TemplateKeyError('Item has no index, key or attribute %r.' % needle) TemplateKeyError: Item has no index, key or attribute 'decimal'.
Associated revisions
History
#1 Updated by Jan Klopper over 12 years ago
2nd trace:
Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 639, in __init__ self.handle() File "/usr/lib/python2.7/BaseHTTPServer.py", line 343, in handle self.handle_one_request() File "/home/janklopper/uweb/standalone.py", line 84, in handle_one_request self.server.router(self) File "/home/janklopper/uweb/__init__.py", line 133, in RequestHandler response = pages.InternalServerError(*sys.exc_info()) File "/home/janklopper/uweb/pagemaker/__init__.py", line 345, in InternalServerError 'traceback': self._ParseStackFrames(traceback)}} File "/home/janklopper/uweb/pagemaker/__init__.py", line 307, in _ParseStackFrames 'locals': sorted(frame.f_locals.items()), File "/home/janklopper/uweb/templateparser.py", line 84, in items return list(self.iteritems()) File "/home/janklopper/uweb/templateparser.py", line 72, in <genexpr> return ((key, self[key]) for key in self) File "/home/janklopper/uweb/templateparser.py", line 59, in __getitem__ return self._tags[key].GetValue(self._values) File "/home/janklopper/uweb/templateparser.py", line 627, in GetValue value = self._GetIndex(value, index) File "/home/janklopper/uweb/templateparser.py", line 716, in _GetIndex raise TemplateKeyError('Item has no index, key or attribute %r.' % needle) TemplateKeyError: Item has no index, key or attribute 'Decimal'.
#2 Updated by Elmer de Looff over 12 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 70
Applied in changeset 4120ad4a2cfd.
#3 Updated by Elmer de Looff over 12 years ago
- Category set to TemplateParser
Jan,
This should be fixed, could you please verify?
#4 Updated by Jan Klopper over 12 years ago
- Category deleted (
TemplateParser) - Status changed from Resolved to Closed
- % Done changed from 70 to 100
works as expected! thnx
Added 'items', 'values' and 'sorted' TemplateTag functions, allowing the InternalServerError handler to delegate iteration over possibly unsafe local variables to the template. Also added iteration methods for the IndexedFieldStorage, further reducing the need for iteration to be directed by the DebuggingPageMaker. This resolves #855.