13.1 TemplateFilterModule overly greedy when matching closed module tags

10 views
Skip to first unread message

Captain Oli

unread,
Sep 8, 2013, 9:19:47 AM9/8/13
to nooku-f...@googlegroups.com
Hi

I've noticed that TemplateFilterModule is being overly greedy since the latest framework update to move to HTML5 type tags

The problem is as follows:

There are 2 types of module tags, open tags and closed tags.

Open tags take the following syntax:

<ktml:modules position="left">
    <ktml:modules:content>
</ktml:modules>

and closed tags take this syntax:

<ktml:modules position="left">

Previously, closed tags conformed to the XHML standard with a /> at the end, and thus could be differentiated from open when doing regex replacements.

Now however, the start of the open tag, and the closed tags have the same format, doing a regex replacement becomes harder.

The order in which the tags are replaced has now been swapped, with open tags being replaced first and closed second. The first part of an open tag (<ktml:modules position="left">) is the same as a closed tag (<ktml:modules position="left">), and thus the open tag must be replaced first in order for it not to be misinterpreted as a closed tag. Whilst this does work, there is an issue when using both open and closed tags in the same template.

Take the following example:

In the main template (/applications/site/component/application/view/page/templates/default.php), add the following below the "user4" module tag:

    <ktml:modules:content>
</ktml:modules>

thus making:

            <div>
                <ktml:modules position="user3">
            </div>
            <ktml:modules position="user4">
           <ktml:modules:content>
            </ktml:modules>

This is perfectly valid, and the "user4" tag should be replaced first, followed by the user3 tag. However, regex matches from the "user3" tag, through to the closing tag of the "user4":

(place var_dump/breakpoint in TemplateFilterModule line 154:

array(4) {
  [0]=>
  array(1) {
    [0]=>
    string(158) "
<ktml:modules position="user3">

</div>
<ktml:modules position="user4">
<ktml:modules:content>
</ktml:modules>
" } [1]=> array(1) { [0]=> string(5) "user3" } [2]=> array(1) { [0]=> string(0) "" } [3]=> array(1) { [0]=> string(112) "
</div>
<ktml:modules position="user4">
<ktml:modules:content>
" } }


This is not correct. The regex should match only:


<ktml:modules position="user4">
    <ktml:modules:content>
</ktml:modules>

However, it's actually matching:

<ktml:modules position="left">
</div>
<ktml:modules position="left">
    <ktml:modules:content>
</ktml:modules>


Regex isn't my greatest skill, however I believe it should be possible with some look aheads, and I had partial success with this.

Hope this is helpful.

Oli

Johan Janssens

unread,
Feb 20, 2014, 10:17:22 AM2/20/14
to nooku-f...@googlegroups.com
Thanks Oli, that makes perfect sense. Can you move this into a ticket please ?

Thanks,

Johan

John Bell

unread,
Feb 20, 2014, 11:04:02 AM2/20/14
to nooku-f...@googlegroups.com
Strikes me that sticking to XHTML compliant tags would be simpler and
easier for syntax highlighters to handle correctly.

John
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Nooku Framework" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to nooku-framewo...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>



Johan Janssens

unread,
Feb 21, 2014, 12:20:57 AM2/21/14
to nooku-f...@googlegroups.com
We decided to use html5 tags in Nooku. XHTML is a little bit old school, syntax highlighter will catch up for sure.

Johan

John Bell

unread,
Mar 14, 2014, 3:49:24 AM3/14/14
to nooku-f...@googlegroups.com
It may be 'old school' but it is not ambiguous.
in application/admin/component/application/view/page/templates/default.html.php:

    <div id="panel-component">
        <ktml:modules position="sidebar">
        <div id="panel-sidebar">
            <ktml:modules:content>
        </div>
        </ktml:modules>

without the <div id="panel-sidebar"> for context, it is hard to see which module </ktml:modules> closes

John

Johan Janssens

unread,
Apr 26, 2016, 5:59:10 PM4/26/16
to Joomlatools Developers, nooku-f...@googlegroups.com
To unsubscribe from this group and stop receiving emails from it, send an email to nooku-framework+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages