[PATCH] Compiler fatal error on unbalanced content tags
"Rich Williams" <[email protected]> Thu, 7 Jun 2007 11:27:44 +0100
| Newsgroups | gmane.comp.web.mason.devel |
|---|---|
| Message-ID | <[email protected]> |
All, I had a stray </&> in a %method, and the compiler died ... Can't use an undefined value as an ARRAY reference at .../HTML/Mason/Compiler.pm line 566 It's the test which is checking for balanced tags which is failing - it works fine for top level components, but not for %def or %method, because comp_with_content_stack is only initialised in start_component, which (as far as I can tell) isn't called for sub-components. The attached patch simply changes the test a little (a similar method is used elsewhere in Compiler.pm). I've also added two new test cases, one to catch unbalanced content ending tags in top-level components, and one to catch them in sub-components. Hope this helps. Have fun, Rich ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Mason-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mason-devel
diff.txt
(text/plain, 1.9 KB)
diff -ru HTML-Mason-1.35/lib/HTML/Mason/Compiler.pm HTML-Mason-1.35-rdw/lib/HTML/Mason/Compiler.pm
--- HTML-Mason-1.35/lib/HTML/Mason/Compiler.pm 2006-10-17 19:58:32.000000000 +0100
+++ HTML-Mason-1.35-rdw/lib/HTML/Mason/Compiler.pm 2007-05-29 15:29:46.000000000 +0100
@@ -563,7 +563,7 @@
my %p = @_;
$self->lexer->throw_syntax_error("Found component with content ending tag but no beginning tag")
- unless @{ $c->{comp_with_content_stack} };
+ unless $c->{comp_with_content_stack} && @{ $c->{comp_with_content_stack} };
my $call = pop @{ $c->{comp_with_content_stack} };
my $call_end = $p{call_end};
Only in HTML-Mason-1.35-rdw: Makefile
diff -ru HTML-Mason-1.35/t/06-compiler.t HTML-Mason-1.35-rdw/t/06-compiler.t
--- HTML-Mason-1.35/t/06-compiler.t 2006-10-17 19:58:32.000000000 +0100
+++ HTML-Mason-1.35-rdw/t/06-compiler.t 2007-05-29 15:29:01.000000000 +0100
@@ -1117,6 +1117,30 @@
#------------------------------------------------------------
+ $group->add_test( name => 'unbalanced_content_block_error',
+ description => 'Detect and report unbalanced </&> tags',
+ interp_params => { enable_autoflush => 0 },
+ component => <<'EOF',
+</&>
+EOF
+ expect_error => qr/content ending tag but no beginning tag/
+ );
+
+#------------------------------------------------------------
+
+ $group->add_test( name => 'unbalanced_content_block_subcomp_error',
+ description => 'Detect and report unbalanced </&> tags in subcomponents',
+ interp_params => { enable_autoflush => 0 },
+ component => <<'EOF',
+<%def test>
+</&>
+</%def>
+EOF
+ expect_error => qr/content ending tag but no beginning tag/
+ );
+
+#------------------------------------------------------------
+
return $group;
}