[Templates-cvs] cvs commit: Template2/lib/Template Provider.pm

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/01/28 08:47:44

  Modified:    lib/Template Provider.pm
  Log:
  * added RELATIVE_PATH regex to match relative paths correctly
    http://tt2.org/pipermail/templates/2005-January/007141.html
  
  Revision  Changes    Path
  2.83      +24 -22    Template2/lib/Template/Provider.pm
  
  Index: Provider.pm
  ===================================================================
  RCS file: /template-toolkit/Template2/lib/Template/Provider.pm,v
  retrieving revision 2.82
  retrieving revision 2.83
  diff -u -r2.82 -r2.83
  --- Provider.pm	2004/12/22 09:35:59	2.82
  +++ Provider.pm	2006/01/28 08:47:44	2.83
  @@ -27,34 +27,21 @@
   #
   #----------------------------------------------------------------------------
   #
  -# $Id: Provider.pm,v 2.82 2004/12/22 09:35:59 abw Exp $
  +# $Id: Provider.pm,v 2.83 2006/01/28 08:47:44 abw Exp $
   #
   #============================================================================
   
   package Template::Provider;
   
  -require 5.004;
  -
   use strict;
  -use vars qw( $VERSION $DEBUG $ERROR $DOCUMENT $STAT_TTL $MAX_DIRS $UNICODE );
  -use base qw( Template::Base );
  +use warnings;
  +use base 'Template::Base'
   use Template::Config;
   use Template::Constants;
   use Template::Document;
   use File::Basename;
   use File::Spec;
   
  -$VERSION  = sprintf("%d.%02d", q$Revision: 2.82 $ =~ /(\d+)\.(\d+)/);
  -
  -# name of document class
  -$DOCUMENT = 'Template::Document' unless defined $DOCUMENT;
  -
  -# maximum time between performing stat() on file to check staleness
  -$STAT_TTL = 1 unless defined $STAT_TTL;
  -
  -# maximum number of directories in an INCLUDE_PATH, to prevent runaways
  -$MAX_DIRS = 64 unless defined $MAX_DIRS;
  -
   use constant PREV   => 0;
   use constant NAME   => 1;
   use constant DATA   => 2; 
  @@ -62,10 +49,21 @@
   use constant NEXT   => 4;
   use constant STAT   => 5;
   
  -$DEBUG = 0 unless defined $DEBUG;
  +our $VERSION = sprintf("%d.%02d", q$Revision: 2.83 $ =~ /(\d+)\.(\d+)/);
  +our $DEBUG   = 0 unless defined $DEBUG;
  +our $ERROR   = ''
   
  +# name of document class
  +our $DOCUMENT = 'Template::Document' unless defined $DOCUMENT;
  +
  +# maximum time between performing stat() on file to check staleness
  +our $STAT_TTL = 1 unless defined $STAT_TTL;
  +
  +# maximum number of directories in an INCLUDE_PATH, to prevent runaways
  +our $MAX_DIRS = 64 unless defined $MAX_DIRS;
  +
   # UNICODE is supported in versions of Perl from 5.007 onwards
  -$UNICODE = $] > 5.007 ? 1 : 0;
  +our $UNICODE = $] > 5.007 ? 1 : 0;
   
   my $boms = [
       'UTF-8'    => "\x{ef}\x{bb}\x{bf}",
  @@ -75,6 +73,10 @@
       'UTF-16LE' => "\x{ff}\x{fe}",
   ];
   
  +# regex to match relative paths
  +our $RELATIVE_PATH = qr[(?:^|/)\.+/];
  +
  +
   # hack so that 'use bytes' will compile on versions of Perl earlier than 
   # 5.6, even though we never call _decode_unicode() on those systems
   BEGIN { 
  @@ -133,7 +135,7 @@
               : ("$name: absolute paths are not allowed (set ABSOLUTE option)",
                  Template::Constants::STATUS_ERROR);
       }
  -    elsif ($name =~ m[^\.+/]) {
  +    elsif ($name =~ m/$RELATIVE_PATH/o) {
           # anything starting "./" is relative to cwd, allowed if RELATIVE set
           ($data, $error) = $self->{ RELATIVE } 
   	    ? $self->_fetch($name) 
  @@ -189,7 +191,7 @@
           $error = "$name: absolute paths are not allowed (set ABSOLUTE option)" 
               unless $self->{ ABSOLUTE };
       }
  -    elsif ($name =~ m[^\.+/]) {
  +    elsif ($name =~ m[$RELATIVE_PATH]o) {
           # anything starting "./" is relative to cwd, allowed if RELATIVE set
           $error = "$name: relative paths are not allowed (set RELATIVE option)"
               unless $self->{ RELATIVE };
  @@ -1482,8 +1484,8 @@
   
   =head1 VERSION
   
  -2.81, distributed as part of the
  -Template Toolkit version 2.14, released on 04 October 2004.
  +2.82, distributed as part of the
  +Template Toolkit version 2.15, released on 27 January 2006.
   
   =head1 COPYRIGHT