You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Eric B <eb...@hotmail.com> on 2013/10/28 18:57:31 UTC

Infinite Loop using Regexp in definition

I ran into an infinite loop (stack overflow) using the REGEXP in my tiles definition (see http://stackoverflow.com/q/19598873/827480).  Luckily, I ran 
across a similar thread in StackOverflow (http://stackoverflow.com/a/6617343/827480) that pointed me in the right direction, or I would never have 
caught on.

Basing myself on the example from the http://tech.finn.no/2012/07/25/the-ultimate-view-tiles-3/ site, I tried to create a REGEXP deinition as follows:

Given the following tiles.xml definition file:

<definition name="REGEXP:(.+)" template="/WEB-INF/views/tiles/layouts/default.jsp">
     <put-attribute name="meta" value="/WEB-INF/views/tiles/{1}/meta.jsp"/>
     <put-attribute name="head" value="/WEB-INF/views/tiles/{1}/head.jsp"/>
     <put-attribute name="body" value="/WEB-INF/views/tiles/{1}/body.jsp"/>
</definition>


I would never have expected to run into an infinite loop.  But what seems to be happening, is that the attribute value is being checked against the 
regexp as well.  And given that it matches, it tries to retrieve the value and check that against the regexp ad nauseum.


Although I can theoretically understand the reasoning behind this (allows for recursive template name matching), I'm not entirely sure of the use case 
that it is trying to resolve.

Additionally, I find that the RegexpDefinitionPatternMatcher should be smart enough to detect that it has encountered an infinite loop and throw its 
own error, rather than be stuck in an infinite recursive loop.

Should I be raising this as a bug in Jira, or is this planned/expected behaviour?

Thanks,

Eric


Re: Infinite Loop using Regexp in definition

Posted by Eric B <eb...@hotmail.com>.
On 13-10-28 3:53 PM, Mick Semb Wever wrote:

> We use "REGEXP:([^.]+)\.([^.]+)", and don't come across this behaviour.
> But i would think should still cause the problem you describe above.
>
> I wonder if it's because of a custom DefinitionsFactory that skips
> anything beginning with "/WEB-INF/"… (see p5 of the article),
> Or something else with how our attribute renderers are defined…

I'm not sure, but it is possible.  I'd have to think about that a bit more, and try to figure out the implications.  But I did not (yet) implement the 
concepts you have on page 5 (ie: template definition injections) as I could not easily visualize how that works out, and how it helps in the grand 
scheme, but I may do so yet.

> Anyway, yes you should make the REGEXP something less greedy!
> The article has been updated. There i made it "REGEXP:[^/][^.]*" that is
> anything that doesn't start with a slash is considered a definitions
> name.

Certainly, but making the regex less greedy it resolved the issue.


Re: Infinite Loop using Regexp in definition

Posted by Mick Semb Wever <mc...@apache.org>.
ClamAV 0.96.5


> I ran into an infinite loop [snip]
> 
> Basing myself on the example from the
> http://tech.finn.no/2012/07/25/the-ultimate-view-tiles-3/ site, I
> tried to create a REGEXP deinition as follows:
> 
> Given the following tiles.xml definition file:
> 
> <definition name="REGEXP:(.+)" template="/WEB-INF/views/tiles/layouts/default.jsp">
>      <put-attribute name="meta" value="/WEB-INF/views/tiles/{1}/meta.jsp"/>
>      <put-attribute name="head" value="/WEB-INF/views/tiles/{1}/head.jsp"/>
>      <put-attribute name="body" value="/WEB-INF/views/tiles/{1}/body.jsp"/>
> </definition>


We use "REGEXP:([^.]+)\.([^.]+)", and don't come across this behaviour.
But i would think should still cause the problem you describe above.

I wonder if it's because of a custom DefinitionsFactory that skips
anything beginning with "/WEB-INF/"… (see p5 of the article),
Or something else with how our attribute renderers are defined…

Anyway, yes you should make the REGEXP something less greedy!
The article has been updated. There i made it "REGEXP:[^/][^.]*" that is
anything that doesn't start with a slash is considered a definitions
name.

~mck

-- 
"Everything should be made as simple as possible, but not simpler."
Albert Einstein (William of Ockham) 

| http://github.com/finn-no | http://tech.finn.no |