Skip Menu |

This queue is for tickets about the Config-IniFiles CPAN distribution.

Report information
The Basics
Id: 54997
Status: resolved
Priority: 0/
Queue: Config-IniFiles

People
Owner: Nobody in particular
Requestors: mendoza [...] pvv.ntnu.no
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [patch] stat() on unopened filehandle warning thrown when using filehandle made from a scalar
$ echo -e "[bar]\nfoo=baz_file" > /tmp/lol.ini && PERL5LIB=. perl -wle 'use Config::IniFiles; print "VERSION: $Config::IniFiles::VERSION"; my $a = "[bar]\nfoo=baz_str\n"; open my $sfh, "<", \$a; open my $ffh,"<", "/tmp/lol.ini"; for my $fh ($sfh, $ffh) { my $c = Config::IniFiles->new (-file => $fh); print $c->val("bar","foo");}' VERSION: 2.56 baz_str baz_file $ echo -e "[bar]\nfoo=baz_file" > /tmp/lol.ini && perl -wle 'use Config::IniFiles; print "VERSION: $Config::IniFiles::VERSION"; my $a = "[bar]\nfoo=baz_str\n"; open my $sfh, "<", \$a; open my $ffh,"<", "/tmp/ lol.ini"; for my $fh ($sfh, $ffh) { my $c = Config::IniFiles->new(-file => $fh); print $c->val("bar","foo");}' VERSION: 2.56 stat() on unopened filehandle $sfh at /usr/share/perl5/Config/ IniFiles.pm line 766. baz_str baz_file $ diff /usr/share/perl5/Config/IniFiles.pm Config/IniFiles.pm 764c764 < if (ref($fh) ne "IO::Scalar") --- Show quoted text
> if (ref($fh) ne "IO::Scalar" && -e $fh)
Sorry for the brief description. First oneliner uses my patched version, second staock 2.56 version. Finally there is a diff containing what I believe might fix the issue. Thanks!
On Thu Feb 25 14:08:54 2010, NICOMEN wrote: Show quoted text
> Sorry for the brief description. > > First oneliner uses my patched version, second staock 2.56 version. > > Finally there is a diff containing what I believe might fix the issue. > > Thanks!
Hi! Thanks for your report. Please prepare a patch for this bug using the svn trunk: https://config-inifiles.svn.sourceforge.net/svnroot/config-inifiles/trunk/ Make sure the code is properly indented and formatted, contains regressions tests (add a new file under t/*.t - look at the previous files before that) that fail before the patch to lib/ is applied and succeed afterwards. As it stands it will take me a long time to parse and process your submission. Regards, -- Shlomi Fish
Attached a patch with testcase. Verified failing before applying fix. Hope it's correct ;)
Subject: config-inifiles.patch
Index: t/26scalar-filehandle.t =================================================================== --- t/26scalar-filehandle.t (revisjon 0) +++ t/26scalar-filehandle.t (revisjon 0) @@ -0,0 +1,53 @@ +#!/usr/bin/perl +# This script is a regression test for: +# +# https://rt.cpan.org/Ticket/Display.html?id=45997 +# +# Failure to read the ini file contents from a filehandle made out of a scalar + +use Test::More; + +use strict; +use warnings; + +use Carp qw(cluck); +use English qw(-no_match_vars); + +use Config::IniFiles; + +if ( ! eval { require IO::Scalar; } ) +{ + plan skip_all => "IO::Scalar is not available"; +} +else +{ + plan tests => 2; +} + +{ + my $contents = <<'EOF'; +[section1] +key = val +EOF + + open my $scalar_fh, "<", \$contents; + + my $conf = eval { + $WARNING = 1; + $SIG{__WARN__} = \&Carp::croak; + Config::IniFiles->new( -file => $scalar_fh); + } or warn $EVAL_ERROR; + + # TEST + ok(!$EVAL_ERROR, "Object was initialised from filehandle made out of a scalar."); + + # TEST + is ($conf->val("section1", "key"), + "val", + "Object works." + ); + + undef $conf; + close $scalar_fh; +} + Index: lib/Config/IniFiles.pm =================================================================== --- lib/Config/IniFiles.pm (revisjon 172) +++ lib/Config/IniFiles.pm (arbeidskopi) @@ -761,7 +761,8 @@ } # Get mod time of file so we can retain it (if not from STDIN) - if (ref($fh) ne "IO::Scalar") + # also check if it's a real file (could have been a filehandle made from a scalar). + if (ref($fh) ne "IO::Scalar" && -e $fh) { my @stats = stat $fh; $self->{file_mode} = sprintf("%04o", $stats[2]) if defined $stats[2];
On Mon Mar 01 07:39:32 2010, NICOMEN wrote: Show quoted text
> Attached a patch with testcase. Verified failing before applying fix. > Hope it's correct ;)
Many thanks! I went over your patch and it seemed OK. I just added the necessary entry to the MANIFEST and a change blurb to the Changes. It's now in the repository and is contained in Config-IniFiles-2.57 that was just uploaded to CPAN. Thanks. Resolving as fixed.