| 1 |
|
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
=head1 DESCRIPTION |
| 6 |
|
| 7 |
If an element contains both a default namespace declaration and a second |
| 8 |
namespace declaration, adding an attribute using the default namespace |
| 9 |
declaration will cause that attribute to have the other prefix. |
| 10 |
|
| 11 |
OS Version: FreeBSD 6.3-RELEASE |
| 12 |
Perl Version: v5.8.8 |
| 13 |
LibXML Version: 1.70 |
| 14 |
|
| 15 |
See L<https://rt.cpan.org/Ticket/Display.html?id=55000> . |
| 16 |
|
| 17 |
=cut |
| 18 |
|
| 19 |
use Test::More tests => 6; |
| 20 |
|
| 21 |
use XML::LibXML; |
| 22 |
|
| 23 |
my $xml_string = <<'XML'; |
| 24 |
<?xml version="1.0" encoding="UTF-8"?> |
| 25 |
<element xmlns="uri" |
| 26 |
xmlns:wrong="other"> |
| 27 |
</element> |
| 28 |
XML |
| 29 |
|
| 30 |
my $parser = XML::LibXML->new; |
| 31 |
my $doc = $parser->parse_string($xml_string); |
| 32 |
my $root = $doc->documentElement(); |
| 33 |
$root->setAttributeNS("uri", "prefix:attribute", "text"); |
| 34 |
$root->setAttributeNS("uri", "second", "text"); |
| 35 |
|
| 36 |
my $string = $doc->toString(1); |
| 37 |
|
| 38 |
# TEST |
| 39 |
unlike ($string, qr/[^\w:]attribute="text"/, |
| 40 |
"Not placed as an unprefixed attribute"); |
| 41 |
# TEST |
| 42 |
unlike ($string, qr/\bwrong:attribute="text"/, |
| 43 |
"Not placed in the wrong namespace"); |
| 44 |
|
| 45 |
# TEST |
| 46 |
like ($string, qr/\bprefix:attribute="text"/, |
| 47 |
"Placed in the right namespace"); |
| 48 |
|
| 49 |
# TEST |
| 50 |
unlike ($string, qr/[^\w:]second="text"/, |
| 51 |
"Not placed as an unprefixed attribute"); |
| 52 |
|
| 53 |
# TEST |
| 54 |
unlike ($string, qr/\bwrong:second="text"/, |
| 55 |
"Not placed in the wrong namespace"); |
| 56 |
|
| 57 |
# TEST |
| 58 |
like ($string, qr/\bprefix:second="text"/, |
| 59 |
"Placed in the right namespace"); |
| 60 |
|