Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should not warn about stripped newlines in 2-arg open #15031

Open
p5pRT opened this issue Nov 6, 2015 · 6 comments
Open

should not warn about stripped newlines in 2-arg open #15031

p5pRT opened this issue Nov 6, 2015 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 6, 2015

Migrated from rt.perl.org#126579 (status was 'open')

Searchable as RT126579$

@p5pRT
Copy link
Author

p5pRT commented Nov 6, 2015

From @rjbs

Created by @rjbs

We closed #121085, but it ended by noting this problem​:

  use warnings;

  my $filename = qq{does-not-exist\n};
  open my $fh, "< $filename" or warn "failed to open​: $!";

The above program warns​:

  Unsuccessful open on filename containing newline at program line 5.
  failed to open​: No such file or directory at program line 5.

Two-arg open trims whitespace from the filename, so the filename being
opened does not have a newline in it. The warning is misleading.
If we `touch does-not-exist`, the program runs without warnings, because
the newline is never part of the path being addressed. perl should
only warn when the \n has not been stripped before the open call.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.23.3:

Configured by rjbs at Mon Sep 21 11:54:00 EDT 2015.

Summary of my perl5 (revision 5 version 23 subversion 3) configuration:
   
  Platform:
    osname=darwin, osvers=14.5.0, archname=darwin-2level
    uname='darwin jubjub.local 14.5.0 darwin kernel version 14.5.0: wed jul 29 02:26:53 pdt 2015; root:xnu-2782.40.9~1release_x86_64 x86_64 '
    config_args='-Dprefix=/Users/rjbs/.plenv/versions/23.3 -de -Dusedevel -A'eval:scriptdir=/Users/rjbs/.plenv/versions/23.3/bin''
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -I/opt/local/include',
    optimize='-O3',
    cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -I/opt/local/include'
    ccversion='', gccversion='4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector-strong -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib /opt/local/lib
    libs=-lpthread -lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-lpthread -ldl -lm -lutil -lc
    libc=, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector-strong'



@INC for perl 5.23.3:
    /Users/rjbs/.plenv/versions/23.3/lib/perl5/site_perl/5.23.3/darwin-2level
    /Users/rjbs/.plenv/versions/23.3/lib/perl5/site_perl/5.23.3
    /Users/rjbs/.plenv/versions/23.3/lib/perl5/5.23.3/darwin-2level
    /Users/rjbs/.plenv/versions/23.3/lib/perl5/5.23.3
    .


Environment for perl 5.23.3:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/rjbs
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/rjbs/.plenv/versions/23.3/bin:/Users/rjbs/.plenv/libexec:/Users/rjbs/.plenv/plugins/perl-build/bin:/Users/rjbs/bin:/Users/rjbs/.rbenv/shims:/Users/rjbs/.rbenv/bin:/Users/rjbs/.rakudobrew/bin:/Users/rjbs/.plenv/shims:/Users/rjbs/.plenv/bin:/opt/local/bin:/opt/local/sbin:/usr/local/texlive/2015/bin/x86_64-darwin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/rjbs/code/hla
    PERLDOC=-otext
    PERL_AUTOINSTALL=--skipdeps
    PERL_BADLANG (unset)
    PERL_MAILERS=sendmail:/Users/rjbs/bin/sendmail
    SHELL=/opt/local/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Jan 16, 2016

From @wolfsage

On Fri Nov 06 07​:11​:34 2015, rjbs wrote​:

use warnings;

my $filename = qq{does-not-exist\n};
open my $fh, "< $filename" or warn "failed to open​: $!";

The above program warns​:

Unsuccessful open on filename containing newline at program line 5.
failed to open​: No such file or directory at program line 5.

Shouldn't this warn?

use warnings;

my $filename = qq{does-not-exist\n};
open my $fh, "<", " $filename" or warn "failed to open​: $!";

Also, why does 2-arg-open strip \n and 3-arg-open not?

Is this documented somewhere? Shouldn't these behave the same?

-- Matthew Horsfall (alh)

@p5pRT
Copy link
Author

p5pRT commented Jan 16, 2016

From [Unknown Contact. See original ticket]

On Fri Nov 06 07​:11​:34 2015, rjbs wrote​:

use warnings;

my $filename = qq{does-not-exist\n};
open my $fh, "< $filename" or warn "failed to open​: $!";

The above program warns​:

Unsuccessful open on filename containing newline at program line 5.
failed to open​: No such file or directory at program line 5.

Shouldn't this warn?

use warnings;

my $filename = qq{does-not-exist\n};
open my $fh, "<", " $filename" or warn "failed to open​: $!";

Also, why does 2-arg-open strip \n and 3-arg-open not?

Is this documented somewhere? Shouldn't these behave the same?

-- Matthew Horsfall (alh)

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2016

From @ap

* Matthew Horsfall via RT <perlbug-comment@​perl.org> [2016-01-16 18​:50]​:

Shouldn't this warn?

use warnings;

my $filename = qq{does-not-exist\n};
open my $fh, "&lt;", " $filename" or warn "failed to open​: $!";

Yes it absolutely should.

So the behaviours must flip – the 2-arg open does warn but ought not
while the 3-arg open doesn’t warn but ought to.

Also, why does 2-arg-open strip \n and 3-arg-open not?

Is this documented somewhere? Shouldn't these behave the same?

No they should absolutely not. It is documented right in perlfunc​:

  The filename passed to the one- and two-argument forms of open()
  will have leading and trailing whitespace deleted and normal
  redirection characters honored.

This very fact was the raison d’être for 3-arg open in the first place.
2-arg open has always been this way and could not be changed, but this
behaviour had to be fixed, so 3-arg open was added as an interface which
doesn’t do that.

Regards,
--
Aristotle Pagaltzis // <http​://plasmasturm.org/>

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 24, 2016

From @wolfsage

On Sun, Jan 17, 2016 at 10​:59 PM, Aristotle Pagaltzis <pagaltzis@​gmx.de> wrote​:

So the behaviours must flip – the 2-arg open does warn but ought not
while the 3-arg open doesn’t warn but ought to.

Hmm, it seems strange that we no longer want to warn on 2-arg open.

If a user does this intentionally​:

  open(my $fh, "<somefile\n");

it will fail and may surprise them that it didn't work....

Regardless, thanks for the explanation.

A possible fix is at
http​://perl5.git.perl.org/perl.git/commitdiff/ab3be07ebaf7e0b17d0482e6a74e69074f0f6e33.

-- Matthew Horsfall (alh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants