phptal / PHPTAL

PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages
http://phptal.org
GNU Lesser General Public License v2.1
175 stars 43 forks source link

Throw Exception if metal:use-macro and metal:define-macro both specified for the same element #2

Closed cwisefool closed 12 years ago

cwisefool commented 12 years ago

Fix for an unusual edge case (but tripped me up ;) ): Throws an exception if metal:use-macro and metal:define-macro both specified for the same element. (I had mis-coded a PreFilter so it was generating both which is how I discovered this). (Previously this seemed to cause the page to hang and is certainly an error condition anyway.)

kornelski commented 12 years ago

Good catch, thanks!

Re comment in the code — you can throw PHPTAL_TemplateException.

cwisefool commented 12 years ago

You're welcome. :) [Hadn't used PHPTal_TemplateException, because I couldn't figure out how to get the current line # and file from within the execution context of before() function of PHPTAL_Php_Attribute_METAL_UseMacro, where I made the change.]

By the way, it seems the issue is actually a bit more intractable. For example:

<body>
  <div metal:define-macro="a" metal:use-macro="b"> ... </div>
  <div metal:define-macro="b" metal:use-macro="a"> ... </div>
</body>

generates this kind of error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to

allocate 261900 bytes) in /root/PHPTAL/classes/PHPTAL.php on line 79

i.e. we run into the 'Tree: a developed seed; Seed: an undeveloped tree' type recursion. Of course fixing this kind of recursion might be pretty tricky, and of course it's completely nonsense to write a template that way, but I just thought I'd bring it to your attention anyway as something to maybe note in the docs. :)

On Sat, Mar 31, 2012 at 10:49 PM, porneL < reply@reply.github.com

wrote:

Good catch, thanks!

Re comment in the code you can throw PHPTAL_TemplateException.


Reply to this email directly or view it on GitHub: https://github.com/pornel/PHPTAL/pull/2#issuecomment-4862447