create new tag
, view all tags

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)


TWiki version: TWikiRelease01Feb2003
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: RedHat Linux kernel 2.4.21-ac4 SMP
Web server: Apache/1.3.27
Perl version: v5.6.1 built for i386-linux
Client OS: Win XP
Web Browser: Netscape 7.1

-- 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{"TWiki06x00.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

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2003-12-16 - RichardWilliamson
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.