thimble icon indicating copy to clipboard operation
thimble copied to clipboard

Block Variable Regex is too greedy

Open mwunsch opened this issue 13 years ago • 0 comments

If you look at Redux's jump pagination implementation:

{block:Pagination}
    <div id="navigation" {block:IfEnableJumpPagination}class="jump_pagination"{/block:IfEnableJumpPagination}>
        {block:PreviousPage}<a href="{PreviousPage}">&larr; {lang:Previous}</a>{/block:PreviousPage}

        {block:IfEnableJumpPagination}
            {block:JumpPagination length="5"}
                {block:CurrentPage}
                    <span class="current_page">{PageNumber}</span>
                {/block:CurrentPage}

                {block:JumpPage}
                    <a class="jump_page" href="{URL}">{PageNumber}</a>
                {/block:JumpPage}

            {/block:JumpPagination}
        {/block:IfEnableJumpPagination}

        {block:NextPage}<a href="{NextPage}">{lang:Next page} &rarr;</a>{/block:NextPage}
    </div>
{/block:Pagination}

There's an issue with the IfEnableJumpPagination block: it will devour until the second {/block:IfEnableJumpPagination}. That's not what we want, we want it to devour to the closest close block. I don't have enough regex magical ability to figure this one out though.

When I do something like this:

preg_match($this->block_pattern("If$block_name"), $doc, $matchy);
print_r($matchy);

$matchy[0] looks like this:

{block:ifenablejumppagination}class="jump_pagination">
                {block:PreviousPage}<a href="{PreviousPage}">&larr; {lang:Previous}</a>{/block:PreviousPage}

                {block:IfEnableJumpPagination}
                    {block:JumpPagination length="5"}
                        {block:CurrentPage}
                            <span class="current_page">{PageNumber}</span>
                        {/block:CurrentPage}

                        {block:JumpPage}
                            <a class="jump_page" href="{URL}">{PageNumber}</a>
                        {/block:JumpPage}

                    {/block:JumpPagination}
                {/block:IfEnableJumpPagination}

How do fix?

mwunsch avatar Sep 20 '10 03:09 mwunsch