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

/o regexes spreading beyond scope #10759

Closed
p5pRT opened this issue Oct 25, 2010 · 9 comments
Closed

/o regexes spreading beyond scope #10759

p5pRT opened this issue Oct 25, 2010 · 9 comments
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter distro-freebsd type-core type-ithreads type-regex

Comments

@p5pRT
Copy link

p5pRT commented Oct 25, 2010

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

Searchable as RT78564$

@p5pRT
Copy link
Author

p5pRT commented Oct 25, 2010

From yegg@flash.duckduckgo.com

Created by yegg@flash.duckduckgo.com

Test case​:
#!/usr/bin/perl

my @​strings = ('testing','','testing','testing');

foreach my $string (@​strings) {

  print "\nSTRING​: $string\n";

  my $string2 = 'http';
  $string2 =~ /^h(.*)/o;

  my $q = $string;
  my $test = 'testing';
  warn $test =~ /\Q$q\E/;
}

Here's what I think is happening. If you have a an /o regex with a capture clause and it captures something, and then you run a a second regex with a variable, but it set to '', then it uses the first compiled regex instead and doesn't match as you'd expect.

In this example, You'd expect line 14 to warn 1 then nothing, then 1 twice. Instead, you get 1, then nothing the rest of the time.

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.9:

Configured by yegg at Fri Oct  1 21:12:41 EDT 2010.

Summary of my perl5 (revision 5 version 8 subversion 9) configuration:
  Platform:
    osname=freebsd, osvers=7.0-release-p3, archname=i386-freebsd-64int
    uname='freebsd flash.duckduckgo.com 7.0-release-p3 freebsd 7.0-release-p3 #14: sat aug 30 21:51:38 edt 2008 root@flash.duckduckgo.com:usrobjusrsrcsysprd i386 '
    config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.9/mach -Dprivlib=/usr/local/lib/perl5/5.8.9 -Dman3dir=/usr/local/lib/perl5/5.8.9/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.9/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.9 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.8.9/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dinc_version_list=none -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -Doptimize=-O2 -fno-strict-aliasing -pipe -Ud_dosuid -Ui_gdbm -Dusethreads=n -Dusemymalloc=y -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include',
    optimize='-O2 -fno-strict-aliasing -pipe',
    cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.2.1 20070719  [FreeBSD]', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -Wl,-E  -L/usr/local/lib'
    libpth=/usr/lib /usr/local/lib
    libs=-lm -lcrypt -lutil
    perllibs=-lm -lcrypt -lutil
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -Wl,-R/usr/local/lib/perl5/5.8.9/mach/CORE'
    cccdlflags='-DPIC -fPIC', lddlflags='-shared  -L/usr/local/lib'

Locally applied patches:
    defined-or


@INC for perl v5.8.9:
    /usr/local/lib/perl5/5.8.9/BSDPAN
    /usr/local/lib/perl5/site_perl/5.8.9/mach
    /usr/local/lib/perl5/site_perl/5.8.9
    /usr/local/lib/perl5/5.8.9/mach
    /usr/local/lib/perl5/5.8.9
    .


Environment for perl v5.8.9:
    HOME=/home/yegg
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/yegg/bin:/usr/local/aws/ec2-api-tools-1.3-24159//bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Oct 25, 2010

From @ask

In this example, You'd expect line 14 to warn 1 then nothing, then 1 twice. Instead, you get 1,
then nothing the rest of the time.

I get 1, undef, 1, 1 as expected with 5.12.2 and the Apple provided 5.10.0 and 5.8.9 on OS X.

@p5pRT
Copy link
Author

p5pRT commented Oct 25, 2010

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

@p5pRT
Copy link
Author

p5pRT commented Oct 25, 2010

From yegg@alum.mit.edu

On Mon Oct 25 11​:04​:59 2010, ask wrote​:

In this example, You'd expect line 14 to warn 1 then nothing, then 1
twice. Instead, you get 1,
then nothing the rest of the time.

I get 1, undef, 1, 1 as expected with 5.12.2 and the Apple provided
5.10.0 and 5.8.9 on OS X.

Here's someone else with 5.12.2 that confirms the bug​:
http​://www.perlmonks.org/?node_id=867286 (with a trace).

@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2010

From @ikegami

As explained on PerlMonks, that is the documented behaviour of the empty
pattern.

$ perl -E'say "a" =~ /(.)/; say "b" =~ //; say "c" =~ /\Q\E/; say "d" =~
/(?​:)/'
a
b
c
1

The last shows a possible workaround if you want to an empty pattern to
match anything.

Now, you might say \Q and \E are there, so it's not empty. \Q and \E are
not regex instructions. They are processed when the literal is turned
into a pattern, so the regex compiler doesn't see them.

Does that qualify as a bug? Perhaps, so I'm not rejecting.

@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2010

From @pjcj

On Mon, Oct 25, 2010 at 10​:03​:27AM -0700, yegg@​flash.duckduckgo.com wrote​:

# New Ticket Created by yegg@​flash.duckduckgo.com
# Please include the string​: [perl #78564]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=78564 >

This is a bug report for perl from yegg@​flash.duckduckgo.com,
generated with the help of perlbug 1.39 running under perl v5.8.9.

-----------------------------------------------------------------
[Please describe your issue here]

Test case​:
#!/usr/bin/perl

my @​strings = ('testing','','testing','testing');

foreach my $string (@​strings) {

print "\\nSTRING&#8203;: $string\\n";

my $string2 = 'http';
$string2 =~ /^h\(\.\*\)/o;

my $q = $string;
my $test = 'testing';
warn $test =~ /\\Q$q\\E/;

}

Here's what I think is happening. If you have a an /o regex with a capture clause and it captures something, and then you run a a second regex with a variable, but it set to '', then it uses the first compiled regex instead and doesn't match as you'd expect.

In this example, You'd expect line 14 to warn 1 then nothing, then 1 twice. Instead, you get 1, then nothing the rest of the time.

The behaviour here seems to depend on whether or not usethreads is defined.
With it defined you get the behaviour you had expected.

--
Paul Johnson - paul@​pjcj.net
http​://www.pjcj.net

@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2010

From @ikegami

On Mon Oct 25 17​:24​:02 2010, ikegami@​adaelis.com wrote​:

...

I withdraw what I said. While true, it has nothing to do with the bug
report. Long day.

@khwilliamson
Copy link
Contributor

I ran 5.35.10 unthreaded and threaded and got identical results:

`STRING: testing
1 at /home/khw/perl/bugs/10759.pl line 14.

STRING:
Warning: something's wrong at /home/khw/perl/bugs/10759.pl line 14.

STRING: testing
1 at /home/khw/perl/bugs/10759.pl line 14.

STRING: testing
1 at /home/khw/perl/bugs/10759.pl line 14.
`
I think this is closable

@khwilliamson khwilliamson added the Closable? We might be able to close this ticket, but we need to check with the reporter label Apr 14, 2022
@hvds
Copy link
Contributor

hvds commented Apr 14, 2022

I think this is closable

Yes, it was fixed by 3cb4cde as part of 5.28. Closing.

@hvds hvds closed this as completed Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter distro-freebsd type-core type-ithreads type-regex
Projects
None yet
Development

No branches or pull requests

4 participants