Subject: | [PATCH] dataElements namespace attributes not properly expanded |
Date: | Mon, 1 Dec 2008 15:43:58 -0500 |
To: | bug-XML-Writer [...] rt.cpan.org |
From: | Yanick Champoux <yanick [...] babyl.dyndns.org> |
In the function dataElement, the name of attributes
are stringified by the casting into a hash:
my ($self, $name, $data, %atts) = (@_);
Which is all good and proper, unless an attribute is using
namespaces and passed as an array reference ( e.g.,
[ $ns => 'foo' ]). In that case, the array ref
is turned into a regular string, and the expansion
is not done.
I'm including a patch that contains a testcase that
document the bug, and the fix for it.
---
Writer.pm | 4 ++--
t/dataElement_ns.t | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
create mode 100644 t/dataElement_ns.t
diff --git a/Writer.pm b/Writer.pm
index 892c40f..2f8e458 100644
--- a/Writer.pm
+++ b/Writer.pm
@@ -575,8 +575,8 @@ sub endTag {
# Write a simple data element.
#
sub dataElement {
- my ($self, $name, $data, %atts) = (@_);
- $self->startTag($name, %atts);
+ my ($self, $name, $data, @atts) = (@_);
+ $self->startTag($name, @atts);
$self->characters($data);
$self->endTag($name);
}
diff --git a/t/dataElement_ns.t b/t/dataElement_ns.t
new file mode 100644
index 0000000..091de44
--- /dev/null
+++ b/t/dataElement_ns.t
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use XML::Writer;
+
+my $output;
+
+my $writer = XML::Writer->new( OUTPUT => \$output, NAMESPACES => 1 );
+
+$writer->startTag( 'doc' );
+
+my $ns = 'http://foo';
+
+$writer->addPrefix( $ns => 'foo' );
+
+$writer->dataElement( [ $ns => 'bar' ], 'yadah', [ $ns => 'baz' ] => 'x' );
+
+$writer->endTag( 'doc' );
+
+like $output => qr/foo:bar/, 'element has namespace';
+like $output => qr/foo:baz/, 'attribute has namespace';
+
+
+
+
+
--
1.6.0.3