Really fix @INC munging of the taint test
[dbsrgits/DBIx-Class.git] / t / 54taint.t
index db350d7..d6e3535 100644 (file)
@@ -6,9 +6,30 @@
 use strict;
 use warnings;
 
+# When in taint mode, PERL5LIB is ignored (but *not* unset)
+# Put it back in INC so that local-lib users can actually
+# run this test. Use lib.pm instead of an @INC unshift as
+# it will correctly add any arch subdirs encountered
+use Config;
+
+use lib (
+  grep { length }
+    map { split /\Q$Config{path_sep}\E/, (/^(.*)$/)[0] }  # untainting regex
+      grep { defined }
+        @ENV{qw(PERL5LIB PERLLIB)}  # precedence preserved by lib
+);
+
+# We need to specify 'lib' here as well because even if it was already in
+# @INC, the above will have put our local::lib in front of it, so now an
+# installed DBIx::Class will take precedence over the one we're trying to test.
+# In some cases, prove will have supplied ./lib as an absolute path so it
+# doesn't seem worth trying to remove the second copy since it won't hurt
+# anything.
+use lib qw(t/lib lib);
+
 use Test::More;
 use Test::Exception;
-use lib qw(t/lib);
+use DBICTest;
 
 throws_ok (
   sub { $ENV{PATH} . (kill (0)) },