Daniel Jakob | 1 May 2012 10:36
Favicon

PHP segfaults due Exception in SaxXmlParser

Hi list

After upgrading TAL to 1.2.2, I found a little problem which makes TAL
quite unuseable in scenarios, when you are not able to control the given
xhtml source. Maybe, the problem depends on newer php versions and/or
eaccelerator.

SaxXmlParser::parseString() throws a PHPTAL_ParserException which isn't
catched by the try/catch block which leads directly to an apache
segfault.
The only exception which gets catched is the PHPTAL_TemplateException.
The ParserException subclasses the TemplateException but - however - php
doesn't care about it. This happens every time when I access the script
BUT not the first time. Setting forceReparse to true also 'fixes' the
problem so I assume, the problem is somewhere between the phptal cache
files and the exceptions in php. Maybe, the eaccelerator is involved,
too.
What definitely helps is to explicitly catch PHPTAL_ParserException at
the end of the switch-block (like the TemplateException does).

A sample:

test.xhtml:

<html>
<body>
<span style="" style="">I kill the parser</span>
</body>
</html>

(Continue reading)

ajcrites | 1 May 2012 14:43
Picon
Gravatar

Re: PHP segfaults due Exception in SaxXmlParser

I highly doubt that apache is seg-faulting. If you are getting a 500 that could just mean that your error
reporting is off.
Sent via BlackBerry by AT&T

-----Original Message-----
From: Daniel Jakob <jakob <at> sc-networks.com>
Sender: phptal-bounces <at> lists.motion-twin.com
Date: Tue, 01 May 2012 10:36:48 
To: <phptal <at> lists.motion-twin.com>
Reply-To: Template Attribute Language for PHP <phptal <at> lists.motion-twin.com>
Subject: [PHPTAL] PHP segfaults due Exception in SaxXmlParser

Hi list

After upgrading TAL to 1.2.2, I found a little problem which makes TAL
quite unuseable in scenarios, when you are not able to control the given
xhtml source. Maybe, the problem depends on newer php versions and/or
eaccelerator.

SaxXmlParser::parseString() throws a PHPTAL_ParserException which isn't
catched by the try/catch block which leads directly to an apache
segfault.
The only exception which gets catched is the PHPTAL_TemplateException.
The ParserException subclasses the TemplateException but - however - php
doesn't care about it. This happens every time when I access the script
BUT not the first time. Setting forceReparse to true also 'fixes' the
problem so I assume, the problem is somewhere between the phptal cache
files and the exceptions in php. Maybe, the eaccelerator is involved,
too.
What definitely helps is to explicitly catch PHPTAL_ParserException at
(Continue reading)

Daniel Jakob | 1 May 2012 16:09
Favicon

Re: PHP segfaults due Exception in SaxXmlParser

On Tue, 2012-05-01 at 12:43 +0000, ajcrites@... wrote:
> I highly doubt that apache is seg-faulting. If you are getting a 500 that could just mean that your error
reporting is off.

You're right for versions prior to 1.2.2. But in the current version, it
really leads to a crash of the child process. The crash shows up in the
apache error log.

[Tue May 01 10:05:06 2012] [notice] child pid 24285 exit signal
Segmentation fault (11)
[Tue May 01 10:24:32 2012] [notice] child pid 24252 exit signal
Segmentation fault (11)

> 
> -----Original Message-----
> From: Daniel Jakob <jakob@...>
> Sender: phptal-bounces@...
> Date: Tue, 01 May 2012 10:36:48 
> To: <phptal@...>
> Reply-To: Template Attribute Language for PHP <phptal@...>
> Subject: [PHPTAL] PHP segfaults due Exception in SaxXmlParser
> 
> Hi list
> 
> After upgrading TAL to 1.2.2, I found a little problem which makes TAL
> quite unuseable in scenarios, when you are not able to control the given
> xhtml source. Maybe, the problem depends on newer php versions and/or
> eaccelerator.
> 
> SaxXmlParser::parseString() throws a PHPTAL_ParserException which isn't
(Continue reading)

Hisateru Tanaka | 1 May 2012 17:45
Picon
Gravatar

Re: PHP segfaults due Exception in SaxXmlParser

I know that eAccelerator can't handle try-catch block correctly at least in my experience.
In the other hand, PHPTAL uses its special exception handler if exception is finally
passed to outside. They might relate each other on modern PHP, I guess...

How would below(ugly code) work?

// setup $template here

try {
    echo $template->execute();
    $__dummy = 1;  // Avoiding eAccelerator's bug. 
}
catch(Exception $e) {
    $exception = $e;
}
if(isset($exception)) {
    // echo and exit or...
    $handler = new PHPTAL_ExceptionHandler($template->getEncoding());
    $handler->_defaultExceptionHandler($exception);
}

On 2012/05/01, at 23:09, Daniel Jakob wrote:

> On Tue, 2012-05-01 at 12:43 +0000, ajcrites@... wrote:
>> I highly doubt that apache is seg-faulting. If you are getting a 500 that could just mean that your error
reporting is off.
> 
> You're right for versions prior to 1.2.2. But in the current version, it
> really leads to a crash of the child process. The crash shows up in the
> apache error log.
(Continue reading)

Pierre-Olivier Vares | 9 May 2012 14:32
Picon

Bug when popping context

I got the following recursive structure :

<ul>
  <li metal:use-macro="menu_item">
    <tal:block metal:fill-slot="texte">File</tal:block>
    <tal:block metal:fill-slot="sous-menu">
      <ul>
        <li metal:use-macro="menu_item" tal:define="buggy string:">
          <tal:block metal:fill-slot="texte">Open</tal:block>
	</li>
      </ul>
    </tal:block>
  </li>
</ul>

<tal:block metal:define-macro="menu_item">
  <li class="menu_item">
    <a href="#"><tal:block metal:define-slot="texte" /></a>
    <tal:block metal:define-slot="sous-menu" />
  </li>
</tal:block>

Instead of
* File
  * Open

the result is :
* Open
  * Open

(Continue reading)

Kornel Lesiński | 9 May 2012 21:54
Gravatar

Re: Bug when popping context

On Wed, 09 May 2012 13:32:28 +0100, Pierre-Olivier Vares  
<pov@...> wrote:

> I dropped this piece of code - I never use tal:define and  
> metal:fill-slot in the same time. But has anybody an idea of a proper  
> solution, correcting the 2 bugs ?

Yeah, it's a tricky piece of code. I've been going back and forth on this  
for a while.

I wonder whether stack of contexts for macros should be handled separately  
(pushSlotContext() rather than pushContext())...

--

-- 
regards, Kornel Lesiński
Pierre-Olivier Vares | 11 May 2012 14:47
Picon

Re: Bug when popping context

Kornel Lesiński <kornel <at> ...> writes:

> 
> On Wed, 09 May 2012 13:32:28 +0100, Pierre-Olivier Vares  
> <pov <at> ...> wrote:
> 
> > I dropped this piece of code - I never use tal:define and  
> > metal:fill-slot in the same time. But has anybody an idea of a proper  
> > solution, correcting the 2 bugs ?
> 
> Yeah, it's a tricky piece of code. I've been going back and forth on this  
> for a while.
> 
> I wonder whether stack of contexts for macros should be handled separately  
> (pushSlotContext() rather than pushContext())...
> 

IMHO :
- separate slot contexts and var contexts seems (for me, but I just skimmed
through the code) risky : I'm afraid it generates other problems.

- metal:fill-slot is somehow incompatible with any other attributes (but, if you
did the modification, that's you encountered the case)

Therefore, if this was my code, I'd rather implement the following behaviour :
Treat automatically
  <tag metal:fill-slot [other_attrs]>
as
  <tal:block metal:fill-slot><tag [other_attrs]>

(Continue reading)

Thomas Tanghus | 12 May 2012 11:53
X-Face
Favicon
Gravatar

Variables in i18n:attributes

Hi

I started playing around with phptal this week because I wanted to see if it 
was possible to use as a templating system in ownCloud ( http://owncloud.org 
).
It turned out to be very easy to integrate, and I've only stumbled over one 
problem, and that doesn't have anything to do with the integration.

I have a div where I wan't to translate the title dialog which contains a 
variable assign from my template class with PHPTAL::set().

Using the code below shows ${uploadMaxHumanFilesize} as text.

 <div i18n:attributes="title" title="Drop photo to upload (max 
${uploadMaxHumanFilesize} MB)"></div>

Using:

 <div i18n:name="humansize" i18n:attributes="title" title="Drop photo to 
upload (max ${humansize} MB)">${uploadMaxHumanFilesize}</div>

Gives the error "Unable to find variable 'humansize' in current scope in 
/path/to/template"

as does:

 <div i18n:name="humansize" i18n:attributes="title string:photo to upload (max 
${humansize} MB)">${uploadMaxHumanFilesize}</div>

What is actually worse is that simply using i18n:name removes the entire 
(Continue reading)

Thomas Tanghus | 16 May 2012 13:46
X-Face
Favicon
Gravatar

Re: Variables in i18n:attributes

On Saturday 12 May 2012 11:53 Thomas Tanghus wrote:
> Hi
> 
> I started playing around with phptal this week because I wanted to see if it
> was possible to use as a templating system in ownCloud (
> http://owncloud.org ).
> It turned out to be very easy to integrate, and I've only stumbled over one
> problem, and that doesn't have anything to do with the integration.
> 
> I have a div where I wan't to translate the title dialog which contains a
> variable assign from my template class with PHPTAL::set().
> 
> Using the code below shows ${uploadMaxHumanFilesize} as text.
> 
>  <div i18n:attributes="title" title="Drop photo to upload (max
> ${uploadMaxHumanFilesize} MB)"></div>
> 
> Using:
> 
>  <div i18n:name="humansize" i18n:attributes="title" title="Drop photo to
> upload (max ${humansize} MB)">${uploadMaxHumanFilesize}</div>
> 
> Gives the error "Unable to find variable 'humansize' in current scope in
> /path/to/template"
> 
> as does:
> 
>  <div i18n:name="humansize" i18n:attributes="title string:photo to upload
> (max ${humansize} MB)">${uploadMaxHumanFilesize}</div>
> 
(Continue reading)

Robert Goldsmith | 16 May 2012 14:23
Picon

Re: Variables in i18n:attributes

Maybe I've missed something but my interpretation of your problem is that you want to add variable content
into a translation string for an attribute.

How about something like:

<div i18n:attributes="title" title="titleTranslationKey">
	<tal:block i18n:name="maxFilesize" tal:content="uploadMaxHumanFilesize" />
</div>

with a po file (assuming you are using gettext) of:

msgid "titleTranslationKey"
msgstr "Drop photo to upload (max ${maxFilesize} MB)"

I am assuming here that the i18n:name key/value pairs are available for attribute translation in the same
way they would be for content translation but I haven't seen why that wouldn't be the case.

Robert
----
Robert Goldsmith
rgoldsmith@...

On 16 May 2012, at 12:46, Thomas Tanghus wrote:

> On Saturday 12 May 2012 11:53 Thomas Tanghus wrote:
>> Hi
>> 
>> I started playing around with phptal this week because I wanted to see if it
>> was possible to use as a templating system in ownCloud (
>> http://owncloud.org ).
(Continue reading)


Gmane