Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.91k stars 542 forks source link

Deparse bug: "\::" deparsed as "::" #6405

Closed p5pRT closed 21 years ago

p5pRT commented 21 years ago

Migrated from rt.perl.org#21744 (status was 'resolved')

Searchable as RT21744$

p5pRT commented 21 years ago

From @Juerd

Created by @Juerd

2;0 juerd@​ouranos​:\~$ perl -MO=Deparse -e'print "$foo\​::bar"' print "$foo​::bar"; -e syntax OK 2;0 juerd@​ouranos​:\~$ perl -MO=Deparse -e'print "${foo}​::bar"' print "$foo​::bar"; -e syntax OK

Should be obvious\, I think :)

Below\, characters in the 80th column are doubled because of a shitty terminal. Sorry about that.

Perl Info ``` Flags: category=library severity=medium Site configuration information for perl v5.8.0: Configured by root at Mon Mar 24 20:36:06 CET 2003. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux, osvers=2.4.19-gentoo-r10, archname=i686-linux uname='linux ouranos 2.4.19-gentoo-r10 #3 sun jan 5 22:38:08 cet 2003 i686 aa md athlon(tm) processor authenticamd gnulinux ' config_args='-des -Darchname=i686-linux -Dcc=gcc -Dprefix=/usr -Dvendorprefii x=/usr -Dsiteprefix=/usr -Dlocincpth= -Doptimize=-O2 -march=athlon-tbird -pipe -fomit-frame-pointer -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Dscriptdir=/uu sr/bin -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Di_gdbm -Di_db -Di_ndbm' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undee f useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-DPERL5 -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILEE _OFFSET_BITS=64', optimize='-O2 -march=athlon-tbird -pipe -fomit-frame-pointer ', cppflags='-DPERL5 -DPERL5 -fno-strict-aliasing' ccversion='', gccversion='3.2.2', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksizee =8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lcrypt -lutil perllibs=-lpthread -lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.3.1.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.1' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.0: /usr/lib/perl5/5.8.0/i686-linux /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i686-linux /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i686-linux /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl . --- Environment for perl v5.8.0: HOME=/home/juerd LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/bin:/usr/bin:/bin:/usr/bin:/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr// i686-pc-linux-gnu/gcc-bin/3.2:/usr/X11R6/bin:/opt/blackdown-jdk-1.3.1/bin:/opt/bb lackdown-jdk-1.3.1/jre/bin:/usr/qt/3/bin:/usr/kde/3.1/bin:/usr/games/bin:/opt/vmm ware/bin:/var/qmail/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 21 years ago

From enache@rdslink.ro

On Sat\, Mar 29\, 2003 at 03​:53​:18PM -0000\, Juerd wrote​:

2;0 juerd@​ouranos​:\~$ perl -MO=Deparse -e'print "$foo\​::bar"' print "$foo​::bar"; -e syntax OK 2;0 juerd@​ouranos​:\~$ perl -MO=Deparse -e'print "${foo}​::bar"' print "$foo​::bar"; -e syntax OK

Should this be a solution ?

Regards Adi


Inline Patch ```diff --- /arc/bleadperl/ext/B/B/Deparse.pm 2003-03-25 04:00:20.000000000 +0200 +++ ./ext/B/B/Deparse.pm 2003-03-29 18:49:18.000000000 +0200 @@ -3246,10 +3246,10 @@ my $first = $self->dq($op->first); my $last = $self->dq($op->last); - # Disambiguate "${foo}bar", "${foo}{bar}", "${foo}[1]" + # Disambiguate "${foo}bar", "${foo}{bar}", "${foo}[1]", "$foo\::bar" ($last =~ /^[A-Z\\\^\[\]_?]/ && $first =~ s/([\$@])\^$/${1}{^}/) # "${^}W" etc - || ($last =~ /^[{\[\w_]/ && + || ($last =~ /^[:{\[\w_]/ && $first =~ s/([\$@])([A-Za-z_]\w*)$/${1}{$2}/); return $first . $last; ```
p5pRT commented 21 years ago

From enache@rdslink.ro

On Sat\, Mar 29\, 2003 at 06​:50​:55PM +0200\, I wrote​:

- || ($last =~ /^[{\[\w_]/ && + || ($last =~ /^[​:{\[\w_]/ &&

And \<'> should be probably there too. - || ($last =~ /^[​:{\[\w_]/ && + || ($last =~ /^[​:'{\[\w_]/ &&

$ perl -MO=Deparse "${a}'b" ^D "$a'b";

which perl will parse as $a​::b ...

p5pRT commented 21 years ago

From smcc@mit.edu

"EA" == Enache Adrian \enache@&#8203;rdslink\.ro writes​:

EA> On Sat\, Mar 29\, 2003 at 06​:50​:55PM +0200\, I wrote​: EA> - || ($last =~ /^[{\[\w_]/ && EA> + || ($last =~ /^[​:{\[\w_]/ &&

EA> And \<'> should be probably there too. EA> - || ($last =~ /^[​:{\[\w_]/ && EA> + || ($last =~ /^[​:'{\[\w_]/ &&

EA> $ perl -MO=Deparse EA> "${a}'b" EA> ^D EA> "$a'b";

EA> which perl will parse as $a​::b ...

Yes. It might be better to write the regex as (['\[{\w_]|​::)\, since a single colon doesn't trigger interpretation as a variable\, but generally this is a context where it's better to err on the side of adding the curlies rather than not.

-- Stephen

p5pRT commented 21 years ago

From @rgs

Enache Adrian wrote​:

On Sat\, Mar 29\, 2003 at 06​:50​:55PM +0200\, I wrote​:

- || ($last =~ /^[{\[\w_]/ && + || ($last =~ /^[​:{\[\w_]/ &&

And \<'> should be probably there too. - || ($last =~ /^[​:{\[\w_]/ && + || ($last =~ /^[​:'{\[\w_]/ &&

Thanks\, applied as #19127.

$ perl -MO=Deparse "${a}'b" ^D "$a'b";

which perl will parse as $a​::b ... -- Unlocked is not *NIX

p5pRT commented 21 years ago

From @jhi

The issue got patched\, so I'm marking the problem ticket as resolved.

p5pRT commented 21 years ago

@jhi - Status changed from 'new' to 'resolved'