diff --git a/sax/xml/pct/actions.pm b/sax/xml/pct/actions.pm index 1f53d6c..161ab12 100644 --- a/sax/xml/pct/actions.pm +++ b/sax/xml/pct/actions.pm @@ -121,6 +121,10 @@ method STag($/) { our $elt_stack; $elt_stack.push( $ ); for ( $ ) { + if ( %attr{ $_ } ) { + fire( 'error', + :Exception( "duplicate attribute: " ~ $_ ) ); + } %attr{ $_ } := normalize( $_[0] ); } fire( 'start_element', @@ -140,7 +144,7 @@ method ETag($/) { } else { fire( 'error', - :Exception( "unbalanced end tag: " ~ $ ~ " (" ~ $curr ~ " expected)") ); + :Exception( "unbalanced end tag: " ~ $ ~ " (" ~ $curr ~ " expected)" ) ); } make PCT::Node.new(); } @@ -149,6 +153,10 @@ method ETag($/) { method EmptyElemTag($/) { my %attr; for ( $ ) { + if ( %attr{ $_ } ) { + fire( 'error', + :Exception( "duplicate attribute: " ~ $_ ) ); + } %attr{ $_ } := normalize( $_[0] ); } fire( 'start_element', diff --git a/t/20-element.t b/t/20-element.t index 1cad329..cf4f19f 100644 --- a/t/20-element.t +++ b/t/20-element.t @@ -14,7 +14,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin"; -use Parrot::Test tests => 5; +use Parrot::Test tests => 7; use Test::More; language_output_is( 'xml', <<'CODE', <<'OUT', 'start/end' ); @@ -29,6 +29,12 @@ CODE content OUT +language_output_like( 'xml', <<'CODE', <<'OUT', 'start/end with duplicated attributes' ); +content +CODE +/^duplicate attribute: a\n/ +OUT + language_output_is( 'xml', <<'CODE', <<'OUT', 'empty' ); CODE @@ -41,6 +47,12 @@ CODE OUT +language_output_like( 'xml', <<'CODE', <<'OUT', 'empty with duplicated attributes' ); + +CODE +/^duplicate attribute: a\n/ +OUT + language_output_like( 'xml', <<'CODE', <<'OUT', 'unbalanced start/end' ); content CODE