01506: Malformed pagelist template

Summary: Malformed pagelist template
Created: 2024-05-07 05:56
Status: Open
Category: Bug
From: Petko
Assigned:
Priority: 4
Version: 2.2.33
OS:

Description: Reported by Simon.

Malformed pagelist template with missing/invalid ending anchor, will include more markup than just what is intended, either until an unrelated anchor, or the end of the page.

If a pagelist is positioned below the template it calls, the page may get into an infinite loop and it may be impossible to edit it. --Petko

[[#mytemplate]]
* {=$Name}
[[#invalid anchor here]]

(:pagelist fmt=#mytemplate:)

Maybe discard a template if no ending anchor, but this wouldn't help if there is another anchor further down. Maybe disable nested pagelists, but some wikis may rely on this feature. Maybe disable the loop while editing, but this needs to work with preview. --Petko

Maybe enforce matching anchors, i.e. if [[#mytemplate]] does not have a valid [[#mytemplateend]] then discard the template? simon

How likely is it for pagelist templates to have a different ending anchor? Maybe in a different language it is different? I often use PmForm templates with different anchors [[#nameform]]...[[#namepost]]...[[#nameend]] but these are not pagelist templates. In both cases, the function retrieving the template is the one that would also do (:include Page#mytemplate:) so I'm not sure if it would be modified in the pagelist code or in the include code. --Petko

I didn't realise, until I accidently put a space in the ending anchor, viz [[#mytemplate end]] that it wasn't checked for. Every example I have seen has [[#sometemplatename]] paired with a following [[#sometemplatenameend]].
Of course, this doesn't mean that someone, somewhere hasn't done this (even if accidently) and a change like this could break it.
I would argue that this is a use of anchors for a different syntactic purpose and if we were designing it again we might use, say, directive like markup for templates, e.g. start with
(:template myemplate:) followed by all the template directives and ended by (:templateend mytemplate:). Thus I don't see a problem with enforcing the name of the ending template anchor. simon