Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS / JS expression can lead to traceback in plone.resourceregistries viewlet #200

Open
laulaz opened this issue May 31, 2020 · 2 comments
Labels

Comments

@laulaz
Copy link
Contributor

laulaz commented May 31, 2020

We had a problem with this expression in CSS / JS conditions :
python:'configure_faceted.html' in request.URL0

We don't know exactly why, but we have edge cases where request is :
<HTTPRequest, URL=None>

thus leading to :
KeyError: 'SERVER_URL'

and the plone.resourceregistries failing to display, resulting in an unstyled website.

Would it be OK for you to change this expression (that's what we did on our sites) to :
python:'URL0' in request and 'configure_faceted.html' in request['URL0']

Thanks for your feedback !


Full related traceback :

2020-05-30 04:26:14 ERROR plone.app.viewletmanager Error while rendering viewlet-manager=plone.htmlhead, viewlet=plone.resourceregistries
Traceback (most recent call last):
  File "/Users/plone/.buildout/eggs/plone.app.viewletmanager-2.0.11-py2.7.egg/plone/app/viewletmanager/manager.py", line 112, in render
    html.append(viewlet.render())
  File "/Users/plone/.buildout/eggs/zope.browserpage-3.12.2-py2.7.egg/zope/browserpage/simpleviewclass.py", line 44, in __call__
    return self.index(*args, **kw)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 125, in __call__
    return self.im_func(im_self, *args, **kw)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 59, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  File "/Users/plone/.buildout/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 132, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations
  File "/Users/plone/.buildout/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 240, in __call__
    interpreter()
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 271, in __call__
    self.interpret(self.program)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret
    handlers[opcode](self, args)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 533, in do_optTag_tal
    self.do_optTag(stuff)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 518, in do_optTag
    return self.no_tag(start, program)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 513, in no_tag
    self.interpret(program)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret
    handlers[opcode](self, args)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 531, in do_optTag_tal
    self.no_tag(stuff[-2], stuff[-1])
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 513, in no_tag
    self.interpret(program)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret
    handlers[opcode](self, args)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 742, in do_insertStructure_tal
    structure = self.engine.evaluateStructure(expr)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/PageTemplates/Expressions.py", line 218, in evaluateStructure
    text = super(ZopeContext, self).evaluateStructure(expr)
  File "/Users/plone/.buildout/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/tales.py", line 696, in evaluate
    return expression(self)
  File "/Users/plone/.buildout/eggs/zope.contentprovider-3.7.2-py2.7.egg/zope/contentprovider/tales.py", line 80, in __call__
    return provider.render()
  File "/Users/plone/.buildout/eggs/zope.viewlet-3.7.2-py2.7.egg/zope/viewlet/manager.py", line 124, in render
    return self.template(viewlets=self.viewlets)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 125, in __call__
    return self.im_func(im_self, *args, **kw)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 59, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  File "/Users/plone/.buildout/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 132, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations
  File "/Users/plone/.buildout/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 240, in __call__
    interpreter()
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 271, in __call__
    self.interpret(self.program)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret
    handlers[opcode](self, args)
  File "/Users/plone/.buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 819, in do_loop_tal
    iterator = self.engine.setRepeat(name, expr)
  File "/Users/plone/.buildout/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/tales.py", line 682, in setRepeat
    expr = self.evaluate(expr)
  File "/Users/plone/.buildout/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/tales.py", line 696, in evaluate
    return expression(self)
  File "/Users/plone/.buildout/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/expressions.py", line 217, in __call__
    return self._eval(econtext)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/PageTemplates/Expressions.py", line 155, in _eval
    return render(ob, econtext.vars)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/PageTemplates/Expressions.py", line 117, in render
    ob = ob()
  File "/Users/plone/.buildout/eggs/Products.ResourceRegistries-2.2.13-py2.7.egg/Products/ResourceRegistries/browser/styles.py", line 21, in styles
    styles = registry.getEvaluatedResources(context)
  File "/Users/plone/.buildout/eggs/Products.ResourceRegistries-2.2.13-py2.7.egg/Products/ResourceRegistries/tools/BaseRegistry.py", line 1054, in getEvaluatedResources
    return [item for item in results if self.evaluate(item, context)]
  File "/Users/plone/.buildout/eggs/Products.ResourceRegistries-2.2.13-py2.7.egg/Products/ResourceRegistries/tools/BaseRegistry.py", line 597, in evaluate
    return self.evaluateExpression(item.getCookedExpression(), context)
  File "/Users/plone/.buildout/eggs/Products.ResourceRegistries-2.2.13-py2.7.egg/Products/ResourceRegistries/tools/BaseRegistry.py", line 626, in evaluateExpression
    return expression(ec)
  File "/Users/plone/.buildout/eggs/Products.CMFCore-2.2.10-py2.7.egg/Products/CMFCore/Expression.py", line 47, in __call__
    res = compiled(econtext)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/Products/PageTemplates/ZRPythonExpr.py", line 48, in __call__
    return eval(self._code, vars, {})
  File "PythonExpr", line 1, in <expression>
  File "/Users/plone/.buildout/eggs/AccessControl-3.0.11-py2.7-macosx-10.13-x86_64.egg/AccessControl/ImplPython.py", line 675, in guarded_getattr
    v = getattr(inst, name)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/HTTPRequest.py", line 1380, in __getattr__
    v = self.get(key, default, returnTaints=returnTaints)
  File "/Users/plone/.buildout/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/HTTPRequest.py", line 1274, in get
    path = [other['SERVER_URL']] + path[:n]
KeyError: 'SERVER_URL'
@avoinea
Copy link
Member

avoinea commented Jun 2, 2020

@laulaz This:

python:'configure_faceted.html' in request.get("URL0", "")

may work as well

@avoinea avoinea added the Bug label Jun 2, 2020
@laulaz
Copy link
Contributor Author

laulaz commented Jun 2, 2020

@laulaz This:

python:'configure_faceted.html' in request.get("URL0", "")

may work as well

@avoinea For any "normal" attribute, yes it works.
But not for URL0 (and other special attributes).

See https://github.com/zopefoundation/Zope/blob/72e339f3a908cc37c8a4fb7b03b816d8a55514f7/src/ZPublisher/HTTPRequest.py#L1281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants