Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
check duplicated attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed May 5, 2009
1 parent 69cf357 commit b5782d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion sax/xml/pct/actions.pm
Expand Up @@ -121,6 +121,10 @@ method STag($/) {
our $elt_stack;
$elt_stack.push( $<Name> );
for ( $<Attribute> ) {
if ( %attr{ $_<Name> } ) {
fire( 'error',
:Exception( "duplicate attribute: " ~ $_<Name> ) );
}
%attr{ $_<Name> } := normalize( $_<AttValue>[0] );
}
fire( 'start_element',
Expand All @@ -140,7 +144,7 @@ method ETag($/) {
}
else {
fire( 'error',
:Exception( "unbalanced end tag: " ~ $<Name> ~ " (" ~ $curr ~ " expected)") );
:Exception( "unbalanced end tag: " ~ $<Name> ~ " (" ~ $curr ~ " expected)" ) );
}
make PCT::Node.new();
}
Expand All @@ -149,6 +153,10 @@ method ETag($/) {
method EmptyElemTag($/) {
my %attr;
for ( $<Attribute> ) {
if ( %attr{ $_<Name> } ) {
fire( 'error',
:Exception( "duplicate attribute: " ~ $_<Name> ) );
}
%attr{ $_<Name> } := normalize( $_<AttValue>[0] );
}
fire( 'start_element',
Expand Down
14 changes: 13 additions & 1 deletion t/20-element.t
Expand Up @@ -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' );
Expand All @@ -29,6 +29,12 @@ CODE
<elt a="1" b="txt">content</elt>
OUT

language_output_like( 'xml', <<'CODE', <<'OUT', 'start/end with duplicated attributes' );
<elt a="1" a='txt' >content</elt >
CODE
/^duplicate attribute: a\n/
OUT

language_output_is( 'xml', <<'CODE', <<'OUT', 'empty' );
<elt />
CODE
Expand All @@ -41,6 +47,12 @@ CODE
<elt a="1"></elt>
OUT

language_output_like( 'xml', <<'CODE', <<'OUT', 'empty with duplicated attributes' );
<elt a='1' a='2'/>
CODE
/^duplicate attribute: a\n/
OUT

language_output_like( 'xml', <<'CODE', <<'OUT', 'unbalanced start/end' );
<a><b>content</c></a>
CODE
Expand Down

0 comments on commit b5782d4

Please sign in to comment.