develooper Front page | perl.perl5.porters | Postings from October 2017

[perl #132334] In Perl 5.26 and above, the /o modifier has sideeffects on split

Thread Previous
From:
Harald Joerg
Date:
October 20, 2017 22:59
Subject:
[perl #132334] In Perl 5.26 and above, the /o modifier has sideeffects on split
Message ID:
rt-4.0.24-5947-1508540392-580.132334-75-0@perl.org
# New Ticket Created by  Harald Joerg 
# Please include the string:  [perl #132334]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132334 >


This is a bug report for perl from Harald.Joerg@arcor.de,
generated with the help of perlbug 1.40 running under perl 5.26.0.

#!/usr/bin/perl -w
# The following test program works fine with Perl 5.24, but fails with
# perlbrew-installed Perl 5.26.0, 5.26.1 and 5.27.1.
#
# No modules beyond Test::More are required.
#
# In the test case, a split procedure takes the separator and the text
# as parameters.  As a special case, a separator of '0' stands for
# 'split on an empty string'.  In the test data we have 'ab', to be
# split on the empty string, and 'a;b', to be split on the
# semicolon. In both cases the result should be the array ('a','b').
# Perl versions up to 5.24 behave as expected, 5.26 and 5.27 fail with
# the second split.

use Test::More;

my @records = (
    { separator => '0', effective => '',  text => 'ab' },
    { separator => ';', effective => ';', text => 'a;b' },
);

for (@records) {
    my ($separator, $effective, $text) = @$_{qw(separator effective text)};

    # The next statement is supposed to replace a separator of '0' by
    # an empty string.	For whatever reason, this substution carries
    # the /o modifier which should be both useless and harmless
    # because there are no variables in the pattern.
    $separator =~ s/0//o; # <---- Easy workaround: remove the /o modifier

    # Just verifying what we're going to pass to the split function:
    is($separator,$effective,"Going to split '$text' with '$separator'");

    my @result = split($separator,$text);

    is_deeply(\@result,['a','b'],"Resulting in ('a','b')");
    # Yet, with Perl 5.26 the split in the second test case behaves if
    # the separator is still the empty string: The semicolon is an
    # element in @result.
}

done_testing;
__END__

This is a breakdown from the TWiki (http://twiki.org) test suite.  I
have eliminated as much as I managed from the code.  The bug only
manifests itself *after* a split on an empty string.
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.26.0:

Configured by haj at Fri Aug 11 22:05:56 CEST 2017.

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=4.9.0-3-amd64
    archname=x86_64-linux
    uname='linux hajdesktop 4.9.0-3-amd64 #1 smp debian 4.9.30-2+deb9u3 (2017-08-06) x86_64 gnulinux '
    config_args='-de -Dprefix=/home/haj/perl5/perlbrew/perls/perl-5.26.0 -Aeval:scriptdir=/home/haj/perl5/perlbrew/perls/perl-5.26.0/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='6.3.0 20170516'
    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='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/6/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.24.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.24'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    Devel::PatchPerl 1.46

---
@INC for perl 5.26.0:
    /home/haj/perl5/perlbrew/perls/perl-5.26.0/lib/site_perl/5.26.0/x86_64-linux
    /home/haj/perl5/perlbrew/perls/perl-5.26.0/lib/site_perl/5.26.0
    /home/haj/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0/x86_64-linux
    /home/haj/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0

---
Environment for perl 5.26.0:
    HOME=/home/haj
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/haj/perl5/perlbrew/bin:/home/haj/perl5/perlbrew/perls/perl-5.26.0/bin:/home/haj/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/haj/devel/twiki/trunk/TWikiDevContrib/tools
    PERL5LIB=
    PERLBREW_LIB=
    PERLBREW_MANPATH=/home/haj/perl5/perlbrew/perls/perl-5.26.0/man
    PERLBREW_PATH=/home/haj/perl5/perlbrew/bin:/home/haj/perl5/perlbrew/perls/perl-5.26.0/bin
    PERLBREW_PERL=perl-5.26.0
    PERLBREW_ROOT=/home/haj/perl5/perlbrew
    PERLBREW_SKIP_INIT=1
    PERLBREW_VERSION=0.78
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=
    SHELL=/bin/bash


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About