Skip to content

Commit

Permalink
Item12952: Use File::Basename to parse
Browse files Browse the repository at this point in the history
Thanks WillNorris for the point-out.
  • Loading branch information
gac410 committed Sep 4, 2014
1 parent 7798c61 commit 3d009b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/lib/Foswiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use warnings;
use Assert;
use Cwd qw( abs_path );
use Error qw( :try );
use File::Basename;
use File::Spec ();
use Monitor ();
use CGI (); # Always required to get html generation tags;
Expand Down Expand Up @@ -384,7 +385,7 @@ BEGIN {
"AUTOCONFIG: Found Bin dir: $bin, Script name: $script using FindBin\n"
if (TRAUTO);

$Foswiki::cfg{ScriptSuffix} = ( $script =~ /(\.[^.]*)$/ ) ? $1 : '';
$Foswiki::cfg{ScriptSuffix} = ( fileparse( $script, qr/\.[^.]*/ ) )[2];
print STDERR
"AUTOCONFIG: Found SCRIPT SUFFIX $Foswiki::cfg{ScriptSuffix} \n"
if ( TRAUTO && $Foswiki::cfg{ScriptSuffix} );
Expand Down
8 changes: 3 additions & 5 deletions core/lib/Foswiki/Configure/Checkers/ScriptSuffix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ package Foswiki::Configure::Checkers::ScriptSuffix;
use strict;
use warnings;

use File::Basename;
use Foswiki::Configure::Checker ();
our @ISA = ('Foswiki::Configure::Checker');

sub check_current_value {
my ( $this, $reporter ) = @_;

# SMELL: On FreeBSD, $0 includes the full path.
# Don't allow any path components to disrupt the suffix
my $currentSuffix = ( $0 =~ /(\.[^.\/]*?)$/ ) ? $1 : '';

my $currentSuffix = ( fileparse( $0, qr/\.[^.]*/ ) )[2];
my $expectedSuffix = $Foswiki::cfg{ScriptSuffix} || '';

if ( $currentSuffix ne $expectedSuffix ) {
$reporter->WARN( <<WHINGE );
This script ($0) does not have the expected {ScriptSuffix} ($expectedSuffix)
This script ($0) suffix ($currentSuffix) does not have the expected {ScriptSuffix} ($expectedSuffix)
WHINGE
}
}
Expand Down

0 comments on commit 3d009b4

Please sign in to comment.