[Catalyst-commits] r6989 - in Catalyst-Runtime/5.70/trunk:
lib/Catalyst t
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Sun Oct 14 18:13:10 GMT 2007
Author: castaway
Date: 2007-10-14 18:13:09 +0100 (Sun, 14 Oct 2007)
New Revision: 6989
Modified:
Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm
Catalyst-Runtime/5.70/trunk/t/unit_utils_load_class.t
Log:
Add tests to not load files that are not valid/sane class names (from theorbtwo)
Modified: Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm 2007-10-14 16:50:16 UTC (rev 6988)
+++ Catalyst-Runtime/5.70/trunk/lib/Catalyst/Utils.pm 2007-10-14 17:13:09 UTC (rev 6989)
@@ -251,6 +251,12 @@
croak "Malformed class Name $class"
if $class =~ m/(?:\b\:\b|\:{3,})/;
+ croak "Malformed class Name $class"
+ if $class =~ m/[^\w:]/;
+
+ croak "ensure_class_loaded should be given a classname, not a filename ($class)"
+ if $class =~ m/\.pm$/;
+
return if !$opts->{ ignore_loaded }
&& Class::Inspector->loaded( $class ); # if a symbol entry exists we don't load again
@@ -258,7 +264,7 @@
my $error;
{
local $@;
- eval "require $class";
+ eval "require $class;";
$error = $@;
}
Modified: Catalyst-Runtime/5.70/trunk/t/unit_utils_load_class.t
===================================================================
--- Catalyst-Runtime/5.70/trunk/t/unit_utils_load_class.t 2007-10-14 16:50:16 UTC (rev 6988)
+++ Catalyst-Runtime/5.70/trunk/t/unit_utils_load_class.t 2007-10-14 17:13:09 UTC (rev 6989)
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 14;
use lib "t/lib";
@@ -49,3 +49,11 @@
eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") };
ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" );
+undef $@;
+eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') };
+like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .');
+
+undef $@;
+eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') };
+like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm');
+
More information about the Catalyst-commits
mailing list