Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

Re: [perl #113094] perlbug AutoReply: Keeping track of 'Unescaped left brace in regex is deprecated'

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


andreas.koenig.7os6VVqR at franz

May 28, 2012, 12:50 AM

Post #1 of 8 (424 views)
Permalink
Re: [perl #113094] perlbug AutoReply: Keeping track of 'Unescaped left brace in regex is deprecated'

Found in GRANTM/XML-Simple-2.18.tar.gz in lib/XML/Simple.pm:

995 $val =~ s{\$\{([\w.]+)\}}{ $self->get_var($1) }ge;
1031 $val =~ s{\$\{(\w+)\}}{ $self->get_var($1) }ge;

% make test
[...]
t/0_Config.t .. Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([\w.]+)}/ at /tmp/tmp.4uMUAQPZaT/XML-Simple-2.18-cUi3UY/blib/lib/XML/Simple.pm line 995.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE (\w+)}/ at /tmp/tmp.4uMUAQPZaT/XML-Simple-2.18-cUi3UY/blib/lib/XML/Simple.pm line 1031.
# Package Version
# perl 5.17.0
# XML::Simple 2.18
# Storable 2.35
# XML::Parser 2.41
# XML::SAX 0.99
# XML::NamespaceSupport 1.11
t/0_Config.t .. ok


Look like perl miscounts one backslash. I would expect that the regexp
is accepted by perl because the brace is escaped.

--
andreas


hv at crypt

May 28, 2012, 11:19 AM

Post #2 of 8 (409 views)
Permalink
Re: [perl #113094] perlbug AutoReply: Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

andreas.koenig.7os6VVqR [at] franz (Andreas J. Koenig) wrote:
:Found in GRANTM/XML-Simple-2.18.tar.gz in lib/XML/Simple.pm:
:
: 995 $val =~ s{\$\{([\w.]+)\}}{ $self->get_var($1) }ge;
: 1031 $val =~ s{\$\{(\w+)\}}{ $self->get_var($1) }ge;
:
:% make test
:[...]
:t/0_Config.t .. Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([\w.]+)}/ at /tmp/tmp.4uMUAQPZaT/XML-Simple-2.18-cUi3UY/blib/lib/XML/Simple.pm line 995.
:Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE (\w+)}/ at /tmp/tmp.4uMUAQPZaT/XML-Simple-2.18-cUi3UY/blib/lib/XML/Simple.pm line 1031.
:# Package Version
:# perl 5.17.0
:# XML::Simple 2.18
:# Storable 2.35
:# XML::Parser 2.41
:# XML::SAX 0.99
:# XML::NamespaceSupport 1.11
:t/0_Config.t .. ok
:
:
:Look like perl miscounts one backslash. I would expect that the regexp
:is accepted by perl because the brace is escaped.

IIRC, when you use a regex metacharacter as a delimiter, escaping it
gives you the metacharacter:

% perl -wle 'print "line\n" =~ m$\$$'
1
%

So I think the warning is correct, though somewhat misleadingly expressed.

I don't remember if there is a way to get past that to match the literal.

Hugo


h.m.brand at xs4all

May 28, 2012, 11:42 PM

Post #3 of 8 (408 views)
Permalink
Re: [perl #113094] perlbug AutoReply: Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

On Mon, 28 May 2012 19:19:25 +0100, hv [at] crypt wrote:

> andreas.koenig.7os6VVqR [at] franz (Andreas J. Koenig) wrote:
> :Found in GRANTM/XML-Simple-2.18.tar.gz in lib/XML/Simple.pm:
> :
> : 995 $val =~ s{\$\{([\w.]+)\}}{ $self->get_var($1) }ge;
> : 1031 $val =~ s{\$\{(\w+)\}}{ $self->get_var($1) }ge;
> :
> :% make test
> :[...]
> :t/0_Config.t .. Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([\w.]+)}/ at /tmp/tmp.4uMUAQPZaT/XML-Simple-2.18-cUi3UY/blib/lib/XML/Simple.pm line 995.
> :Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE (\w+)}/ at /tmp/tmp.4uMUAQPZaT/XML-Simple-2.18-cUi3UY/blib/lib/XML/Simple.pm line 1031.
> :# Package Version
> :# perl 5.17.0
> :# XML::Simple 2.18
> :# Storable 2.35
> :# XML::Parser 2.41
> :# XML::SAX 0.99
> :# XML::NamespaceSupport 1.11
> :t/0_Config.t .. ok
> :
> :
> :Look like perl miscounts one backslash. I would expect that the regexp
> :is accepted by perl because the brace is escaped.
>
> IIRC, when you use a regex metacharacter as a delimiter, escaping it
> gives you the metacharacter:
>
> % perl -wle 'print "line\n" =~ m$\$$'
> 1
> %
>
> So I think the warning is correct, though somewhat misleadingly expressed.
>
> I don't remember if there is a way to get past that to match the literal.
>
> Hugo

Got this report this morning:

http://www.cpantesters.org/cpan/report/b40c2a9c-a87e-11e1-85e6-b1e975b706df

t/11_DDumper.t .... ok

# Failed test 'no warnings'
# at /home/src/perl/repoperls/installed-perls/perl/v5.16.0-226-g760209f/165a/lib/site_perl/5.17.0/Test/NoWarnings.pm line 45.
# There were 1 warning(s)
# Previous test 0 ''
# Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^PVIV\("a\\(n|12)\\342\\202\\254"\\0\) \[UTF8 "a\\?n\\x{ <-- HERE 20ac}"\]/ at t/20_DPeek.t line 72.
# at t/20_DPeek.t line 72.
#
# Looks like you failed 1 test of 50.
t/20_DPeek.t ......
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/50 subtests


code that causes it

SKIP: {
$] <= 5.008001 and skip "UTF8 tests useless in this ancient perl version", 1;
$VAR = "a\x0a\x{20ac}";
like (DPeek ($VAR), qr'^PVIV\("a\\(n|12)\\342\\202\\254"\\0\) \[UTF8 "a\\?n\\x{20ac}"\]',
' $VAR "a\x0a\x{20ac}"');
}


I just added the \ before the { as it passes on 5.8.0 up to blead (64
versions of perl)

--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.14 porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/


public at khwilliamson

Jun 1, 2012, 2:40 PM

Post #4 of 8 (410 views)
Permalink
Re: [perl #113094] [perl #21491] : Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

The example below uses single quotes as qr delimiters

On 05/29/2012 12:42 AM, H.Merijn Brand wrote:
> code that causes it
>
> SKIP: {
> $]<= 5.008001 and skip "UTF8 tests useless in this ancient perl version", 1;
> $VAR = "a\x0a\x{20ac}";
> like (DPeek ($VAR), qr'^PVIV\("a\\(n|12)\\342\\202\\254"\\0\) \[UTF8 "a\\?n\\x{20ac}"\]',
> ' $VAR "a\x0a\x{20ac}"');
> }

Bug #21491 says that single quotes should not interpolate. But this
code assumes that it does. If we fixed #21491, I believe it would break
this code, would it not?

I wonder how much code is out there that depends on #21491 being broken.
We might have to mark it as won't fix, then.


perl.p5p at rjbs

Jun 4, 2012, 4:07 PM

Post #5 of 8 (403 views)
Permalink
Re: [perl #113094] [perl #21491] : Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

* Karl Williamson <public [at] khwilliamson> [2012-06-01T17:40:18]
> Bug #21491 says that single quotes should not interpolate. But this
> code assumes that it does. If we fixed #21491, I believe it would
> break this code, would it not?
>
> I wonder how much code is out there that depends on #21491 being
> broken. We might have to mark it as won't fix, then.

This very naive CPAN search indicates "not much."

http://grep.cpan.me/?q=qr%27%5B%5E%27%5Cn%5D%2B%5C%24%5B%5E%27%5D&page=2

I think that bug should still be fixed.

--
rjbs
Attachments: signature.asc (0.48 KB)


demerphq at gmail

Jun 4, 2012, 11:12 PM

Post #6 of 8 (403 views)
Permalink
Re: [perl #113094] [perl #21491] : Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

On 1 June 2012 23:40, Karl Williamson <public [at] khwilliamson> wrote:
> The example below uses single quotes as qr delimiters
>
> On 05/29/2012 12:42 AM, H.Merijn Brand wrote:
>>
>> code that causes it
>>
>> SKIP: {
>> $]<= 5.008001 and skip "UTF8 tests useless in this ancient perl
>> version", 1;
>> $VAR = "a\x0a\x{20ac}";
>> like (DPeek ($VAR), qr'^PVIV\("a\\(n|12)\\342\\202\\254"\\0\) \[UTF8
>> "a\\?n\\x{20ac}"\]',
>> ' $VAR
>> "a\x0a\x{20ac}"');
>> }
>
>
> Bug #21491 says that single quotes should not interpolate. But this code
> assumes that it does. If we fixed #21491, I believe it would break this
> code, would it not?

Are you sure about that? I don't see any interpolation there. Do you
mean escape handling?

As far as I understand things \\ and \' are *supposed* to be unescaped
inside m''.

So what do you mean by this? I see nothing unexpected here.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"


perl.p5p at rjbs

Jun 5, 2012, 5:26 AM

Post #7 of 8 (402 views)
Permalink
Re: [perl #113094] [perl #21491] : Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

* demerphq <demerphq [at] gmail> [2012-06-05T02:12:29]
> On 1 June 2012 23:40, Karl Williamson <public [at] khwilliamson> wrote:
> >
> > Bug #21491 says that single quotes should not interpolate.  But this code
> > assumes that it does.  If we fixed #21491, I believe it would break this
> > code, would it not?
>
> Are you sure about that? I don't see any interpolation there. Do you
> mean escape handling?
>
> As far as I understand things \\ and \' are *supposed* to be unescaped
> inside m''.
>
> So what do you mean by this? I see nothing unexpected here.

I was confused by this, too, and foolishly didn't go read 21491. This is about
escape sequences, not variable interpolation. I was rushing through my mail
queue and not verifying everything I read. I'm sorry if this lead to spreading
any confusion!

Yes, fixing this looks like it would break the world. In fact, I think the
busted thing is likely the documentation, although it looks like it needs a
careful read before I really state that with confidence.

--
rjbs
Attachments: signature.asc (0.48 KB)


demerphq at gmail

Jun 5, 2012, 6:01 AM

Post #8 of 8 (400 views)
Permalink
Re: [perl #113094] [perl #21491] : Keeping track of 'Unescaped left brace in regex is deprecated' [In reply to]

On 5 June 2012 14:26, Ricardo Signes <perl.p5p [at] rjbs> wrote:
> * demerphq <demerphq [at] gmail> [2012-06-05T02:12:29]
>> On 1 June 2012 23:40, Karl Williamson <public [at] khwilliamson> wrote:
>> >
>> > Bug #21491 says that single quotes should not interpolate. But this code
>> > assumes that it does. If we fixed #21491, I believe it would break this
>> > code, would it not?
>>
>> Are you sure about that? I don't see any interpolation there. Do you
>> mean escape handling?
>>
>> As far as I understand things \\ and \' are *supposed* to be unescaped
>> inside m''.
>>
>> So what do you mean by this? I see nothing unexpected here.
>
> I was confused by this, too, and foolishly didn't go read 21491. This is about
> escape sequences, not variable interpolation. I was rushing through my mail
> queue and not verifying everything I read. I'm sorry if this lead to spreading
> any confusion!

Arent the case that Karl mentioned and the case in the bug different?

The case in the bug comes down to this:

my $pat= "\\n"; print "\n"=~/$pat/;

Which matches, because the toker first turns "\\n" into "\n" and then
hands it to the regex engine which turns the "\n" into a literal $n.

This behaviour has changed over time and the docs should probably
explain that \n IS a regex escape sequence just like \w, which
"happens" to match the same thing that "\n" is unescaped into.

> Yes, fixing this looks like it would break the world. In fact, I think the
> busted thing is likely the documentation, although it looks like it needs a
> careful read before I really state that with confidence.

Well, I can argue the case of: $x="\\n"; "\n"=~/$x/, but the case of
"\n"=~m'\\n' is a lot easier to say is a bug. Even if neither is
entirely clear.

Yves


--
perl -Mre=debug -e "/just|another|perl|hacker/"

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.