This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Forbid source filters in Unicode evals
authorFather Chrysostomos <sprout@cpan.org>
Sun, 30 Oct 2011 02:56:18 +0000 (19:56 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 6 Nov 2011 08:13:46 +0000 (01:13 -0700)
Source filters have always been byte-level filters.  Therefore they
don’t make sense on Unicode strings, unless we are planning to add
new APIs to support it.  Until then, croak.

ext/XS-APItest/t/eval-filter.t
pod/perldiag.pod
toke.c

index 8d370e5..d4a9153 100644 (file)
@@ -1,9 +1,18 @@
 #!perl -w
 use strict;
 
-use Test::More tests => 1;
+use Test::More tests => 3;
 use XS::APItest;
 
+{
+    use feature "unicode_eval";
+    my $unfiltered_foo = "foo";
+    eval "BEGIN { filter() }";
+    like $@, qr/^Source filters apply only to byte streams at /,
+       'filters die under unicode_eval';
+    is "foo", $unfiltered_foo, 'filters leak not out of unicode evals';
+}
+
 BEGIN { eval "BEGIN{ filter() }" }
 
 is "foo", "fee", "evals share filters with the currently compiling scope";
index a477db8..20ee641 100644 (file)
@@ -4334,6 +4334,13 @@ But before sort was a keyword, people sometimes used it as a filehandle.
 (F) A sort comparison subroutine may not return a list value with more
 or less than one element.  See L<perlfunc/sort>.
 
+=item Source filters apply only to byte streams
+
+(F) You tried to activate a source filter (usually by loading a
+source filter module) within a string passed to C<eval>.  This is
+not permitted under the C<unicode_eval> feature.  Consider using
+C<evalbytes> instead.  See L<feature>.
+
 =item splice() offset past end of array
 
 (W misc) You attempted to specify an offset that was past the end of
diff --git a/toke.c b/toke.c
index 43ca704..3720a83 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3839,6 +3839,9 @@ Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
     if (!PL_parser)
        return NULL;
 
+    if (PL_parser->lex_flags & LEX_IGNORE_UTF8_HINTS)
+       Perl_croak(aTHX_ "Source filters apply only to byte streams");
+
     if (!PL_rsfp_filters)
        PL_rsfp_filters = newAV();
     if (!datasv)