This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: don't remove escapes for tabs in patterns
authorDavid Mitchell <davem@iabyn.com>
Thu, 23 Feb 2017 10:53:10 +0000 (10:53 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 5 Jun 2017 11:52:17 +0000 (12:52 +0100)
In the following, the T represents a literal tab character.

/\T/ and /\T/x were being deparsed as /T/ and /T/x.
In the particular case of /\T/x that actually changed the pattern's
meaning.

So don't do that: leave the backslashes alone.

This makes
    ./TEST -deparse t/re/keep_tabs.t
pass.

lib/B/Deparse.pm
lib/B/Deparse.t

index 47b557d..e482810 100644 (file)
@@ -4821,6 +4821,10 @@ sub unback {
 
 # Remove backslashes which precede literal control characters,
 # to avoid creating ambiguity when we escape the latter.
+#
+# Don't remove a backslash from escaped whitespace: where the T represents
+# a literal tab character, /T/x is not equivalent to /\T/x
+
 sub re_unback {
     my($str) = @_;
 
@@ -4841,6 +4845,8 @@ sub re_unback {
 
                 # only remove if the thing following is a control char
                 (?=[[:^print:]])
+                # and not whitespace
+                (?=\S)
             /$1$2/xg;
     return $str;
 }
index 381cc2f..4361967 100644 (file)
@@ -2621,3 +2621,9 @@ my $a;
 /$a(?{ my($x, $y) = (); })/;
 my $r1 = qr/(?{ my($x, $y) = (); })/;
 my $r2 = qr/$a(?{ my($x, $y) = (); })/;
+####
+# don't remove pattern whitespace escapes
+/a\ b/;
+/a\ b/x;
+/a\    b/;
+/a\    b/x;