summaryrefslogtreecommitdiff
path: root/t/io/open.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-05-24 23:13:37 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-06-07 08:18:52 -0700
commitf90b723246c15bceccd726b73c412184c27eca7d (patch)
tree232ebb7140be05ec5b66e575c6975dd6e5341ed2 /t/io/open.t
parent1e00d6e92a9b49086ba010b4c50b9362ce8f2caa (diff)
downloadperl-f90b723246c15bceccd726b73c412184c27eca7d.tar.gz
Make open(... "<&", $fileno) respect magic
A magical variable is never SvPOK, but only SvPOKp. The code for checking whether a duplicatee is a numeric file descriptor was only checking SvPOK. So a regular variable containing a fileno-as-a-string would work, such as the $a below, as would a stringified magical vari- able ("$1"), but not $1 itself. $ echo foo | perl -le '$a = "0"; open a, "<&", $a; warn <a>' foo $ echo foo | perl -le '"0" =~ /(.)/; open a, "<&", $1; warn <a>' Can't use an undefined value as filehandle reference at -e line 1. $ echo foo | perl -le '"0" =~ /(.)/; open a, "<&", "$1"; warn <a>' foo SvPOK variables are also SvPOKp, so checking only the latter suffices.
Diffstat (limited to 't/io/open.t')
-rw-r--r--t/io/open.t6
1 files changed, 5 insertions, 1 deletions
diff --git a/t/io/open.t b/t/io/open.t
index 696ba98acd..e06fc8e394 100644
--- a/t/io/open.t
+++ b/t/io/open.t
@@ -10,7 +10,7 @@ $| = 1;
use warnings;
use Config;
-plan tests => 120;
+plan tests => 121;
my $Perl = which_perl();
@@ -233,6 +233,10 @@ like( $@, qr/Bad filehandle:\s+$afile/, ' right error' );
# used to try to open a file [perl #17830]
ok( open(my $stdin, "<&", fileno STDIN), 'dup fileno(STDIN) into lexical fh') or _diag $!;
+
+ fileno(STDIN) =~ /(.)/;
+ ok open($stdin, "<&", $1), 'open ... "<&", $magical_fileno',
+ || _diag $!;
}
SKIP: {