Source

perl-XML-LibXML / t / 48_rt55000.t

use strict;
use warnings;

=head1 DESCRIPTION

If an element contains both a default namespace declaration and a second
namespace declaration, adding an attribute using the default namespace
declaration will cause that attribute to have the other prefix.

OS Version: FreeBSD 6.3-RELEASE
Perl Version: v5.8.8
LibXML Version: 1.70

See L<https://rt.cpan.org/Ticket/Display.html?id=55000> .

=cut

use Test::More tests => 6;

use XML::LibXML;

my $xml_string = <<'XML';
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns="uri"
xmlns:wrong="other">
</element>
XML

my $parser = XML::LibXML->new;
my $doc = $parser->parse_string($xml_string);
my $root = $doc->documentElement();
$root->setAttributeNS("uri", "prefix:attribute", "text");
$root->setAttributeNS("uri", "second", "text");

my $string = $doc->toString(1);

# TEST
unlike ($string, qr/[^\w:]attribute="text"/,
    "Not placed as an unprefixed attribute");
# TEST
unlike ($string, qr/\bwrong:attribute="text"/, 
    "Not placed in the wrong namespace");

# TEST
like ($string, qr/\bprefix:attribute="text"/,
    "Placed in the right namespace");

# TEST
unlike ($string, qr/[^\w:]second="text"/,
    "Not placed as an unprefixed attribute");

# TEST
unlike ($string, qr/\bwrong:second="text"/,
    "Not placed in the wrong namespace");

# TEST
like ($string, qr/\bprefix:second="text"/,
    "Placed in the right namespace");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.