summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-08-05 22:24:09 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-08-05 22:27:04 -0700
commit7c70caa5333de92b09e138154bed7f78f783be3b (patch)
tree139644b1427743e4e1bafba7b92ff99b9c7c5521 /t
parentc77244152327e2223e55144a463094790d835933 (diff)
downloadperl-7c70caa5333de92b09e138154bed7f78f783be3b.tar.gz
Forbid braces as format delimiters
As long the argument line is not missing, braces can be used for a format: # valid format foo { @<<< $a } but if the argument line is missing, you get a syntax error: # invalid format foo { @<<< } and also if the name is missing: # invalid format { @<<< $a } If you use = then you can use a closing brace to terminate the format, but only if the argument line is missing: # valid, but useless format = @<<< } # invalid format = @<<< $a } In commit 79072805 (perl 5.0 alpha 20), the lexer was changed to lie to the parser about formats’ = and . delimiters, pretending they are actually { and }, because the bracket-handling code takes care of all the scoping issues (well, most of them). Unfortunately, this implementation detail can leak through, but it is far from consistent, as shown above. Fixing this makes it easier to fix other bugs. We do this by recording the fact that we are dealing with a format token before jumping to the bracket code. And we feed format-specific tokens to the parser in that case, so it can’t get fake brackets and real brackets mixed up.
Diffstat (limited to 't')
-rw-r--r--t/op/write.t17
1 files changed, 16 insertions, 1 deletions
diff --git a/t/op/write.t b/t/op/write.t
index a648902fb5..17b8869eb5 100644
--- a/t/op/write.t
+++ b/t/op/write.t
@@ -61,7 +61,7 @@ for my $tref ( @NumTests ){
my $bas_tests = 20;
# number of tests in section 3
-my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 2;
+my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 4;
# number of tests in section 4
my $hmb_tests = 35;
@@ -1002,6 +1002,21 @@ write UNDEF;
pass "freeing current handle in format";
undef $^A;
+ok !eval q|
+format foo {
+@<<<
+$a
+}
+;1
+|, 'format foo { ... } is not allowed';
+
+ok !eval q|
+format =
+@<<<
+}
+;1
+|, 'format = ... } is not allowed';
+
#############################
## Section 4