Bug: Percent include handleIncludeFile doesn't check to see if it is self-referential
If a file percent includes itself directly, any page view of that file, or any file
that includes that file will get into an endless loop.
Test case
I was adding a comment to a page, suggesting that the page was only intended to be included in other pages. So I put an
HTML comment on a page, example 'SomePageName':
<!-- not to be viewed directly! Please use the %INCLUDE{"SomePageName"}% syntax! -->
(I nopped the INCLUDE so that it would display)
Environment
--
RichardWilliamson - 26 Nov 2003
Follow up
TWiki.pm rev:
# 20000501 Kevin Kinnell : changed beta0404 to have many new search
Added lines 1323-1326:
if($theAttributes =~ /$theTopic/) { # buggy. See below.
# looks like we are trying to include ourself. Eheh.
return("Self-Referential Includes. Tsk Tsk.");
}
and the problem went away ...
--
RichardWilliamson - 26 Nov 2003
Good catch.
Of course, the above fix doesn't handle a circular reference (Basic form: file1 includes file2, file2 includes file1). If TWiki plans to handle these cases, it would probably be best to set a specific limit on how deep the INCLUDE recursion can go. Though it's just my preference, it might also be cleaner to just not have a warning and instead just stop the action.
--
TomKagan - 26 Nov 2003
TWiki actually keeps track of included topics, and catches also circular references. Just verified it here on TWiki.org. If you include the topic itself, it does include it once again, but not many times. This is useful if you include one's topic and apply a pattern to grab just part of the topic (e.g. to show a summary)
Just wondering why it would not work in your
TWikiRelease01Feb2003 installation. Please reopen this if you think it is not fixed.
--
PeterThoeny - 01 Dec 2003
I've just tried both self-referential and circular references and as soon as you try
to commit the change that completes the loop, the commit never returns.
Also, with the change above, the " (More options in
WebSearch) " (per web, other than
the TWiki web)
WebSearch links wouldn't resolve correctly (because they are simply INCLUDE{"TWiki06x01.WebSearch"} commands)
This is better:
if(($theAttributes =~ /\"$theTopic\"/) ||
($theAttributes =~ /\"$theWeb\.$theTopic\"/)) {
# looks like we are trying to include ourself. Eheh.
return("Self-Referential Includes. Tsk Tsk.");
}
--
RichardWilliamson - 16 Dec 2003
Fix record