This queue is for tickets about the XML-Simple CPAN distribution.

Report information
The Basics
Id:
95865
Status:
rejected
Priority:
Low/Low
Queue:

People
Owner:
grantm [...] cpan.org
Requestors:
dwest1975 [...] ukr.net
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



MIME-Version: 1.0
X-Spam-Status: No, score=0.362 tagged_above=-99.9 required=10 tests=[BAYES_20=-0.001, DKIM_SIGNED=0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, MSGID_FROM_MTA_HEADER=0.001, T_DKIM_INVALID=0.01] autolearn=no
X-Mailer: mail.ukr.net 5.0
X-Spam-Flag: NO
X-Virus-Checked: Checked
Content-Type: multipart/alternative; boundary="=-bXsXmIaVvOmaLplJMyJB"
Message-ID: <1400767594.410886553.hpg0g9iu@frv37.fwdcdn.com>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-Spam-Score: 0.362
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id E139561E01F for <cpan-bug+xml-simple@hipster.bestpractical.com>; Thu, 22 May 2014 10:08:55 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Np+PrRWokBTh for <cpan-bug+xml-simple@hipster.bestpractical.com>; Thu, 22 May 2014 10:08:54 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 5736161E01D for <bug-xml-simple@rt.cpan.org>; Thu, 22 May 2014 10:08:54 -0400 (EDT)
Received: (qmail 15027 invoked by alias); 22 May 2014 14:08:53 -0000
Received: from frv199.fwdcdn.com (HELO frv199.fwdcdn.com) (212.42.77.199) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Thu, 22 May 2014 07:08:47 -0700
Received: from [10.10.10.37] (helo=frv37.fwdcdn.com) by frv199.fwdcdn.com with smtp ID 1WnTfl-000F1q-Jx for bug-xml-simple@rt.cpan.org; Thu, 22 May 2014 17:08:41 +0300
Received: from dwest1975@ukr.net by frv37.fwdcdn.com; Thu, 22 May 2014 17:08:41 +0300
Authentication-Results: hipster.bestpractical.com (amavisd-new); dkim=softfail (fail, body has been altered) header.i=@ukr.net
Delivered-To: cpan-bug+xml-simple@hipster.bestpractical.com
Subject: Incorrect XML is produced with empty nested arrays
Return-Path: <dwest1975@ukr.net>
X-RT-Mail-Extension: xml-simple
X-Original-To: cpan-bug+xml-simple@hipster.bestpractical.com
X-Spam-Check-BY: la.mx.develooper.com
Dkim-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ukr.net; s=ffe; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:To:Subject:From:Date; bh=zWg1t+FMU23zW/DsCW/wNAPB8r62Q94Ed1OBid3HAdc=; b=LtJ1s96+jutG2UsGUkwKE71AXQauP052APCwPjzXH1V5jiwZq7ncMaTB7AZ3Ed6AW0DVbX9pQaVS6i8CeHPzD9/oMY4eWKNEEqFYW7B44j0rD5RUCWUAZx+DaLlkI3rJ1BlM5NVroY7n7wVUJi87iwvsCkEcBKf0N5M0enFAQoU=;
Date: Thu, 22 May 2014 17:08:41 +0300
X-Spam-Level:
To: bug-XML-Simple@rt.cpan.org
Content-Transfer-Encoding: binary
From: Dean West <dwest1975@ukr.net>
X-RT-Interface: Email
Content-Length: 0
Content-Length: 1889
content-type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 3379
content-type: text/html; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8

Hi,

Recently I noticed, that XML::Simple generates incorrect XML with default options if data has empty nested array(s). Generated node with empty nested array(s) looks like it contains data whereas it actually does not. Here is a simple demonstration:

Show quoted text
> perl -w <<'EOF'
> use XML::Simple;
>
> my $data = {
>     user => [
>         {
>             login => 'bob',
>             password => 'qwerty',
>             options => [],
>         },
>         {
>             login => 'alice',
>             password => 'ytrewq',
>             options => [],
>         },
>     ],
> };
>
> print XMLout($data);
> EOF

It produces the following XML:

<opt>
  <user login="bob" password="qwerty">
  </user>
  <user login="alice" password="ytrewq">
  </user>
</opt>

As you can see content for each 'user' node here is new line and 2 spaces. It stands to reason, that there should be no content at all in this case.

I have prepared a small patch which fixes this issue:

--- a/lib/XML/Simple.pm
+++ b/lib/XML/Simple.pm
@@ -1564,8 +1564,8 @@ sub value_to_xml {
         }

         if(ref($value)  or  $self->{opt}->{noattr}) {
-          push @nested,
-            $self->value_to_xml($value, $key, "$indent  ");
+          $value = $self->value_to_xml($value, $key, "$indent  ");
+          push @nested, $value if($value ne '');
         }
         else {
           $value = $self->escape_value($value) unless($self->{opt}->{noescape});

With this patch the following XML is produced:

<opt>
  <user login="bob" password="qwerty" />
  <user login="alice" password="ytrewq" />
</opt>

Please consider including it in future version.

--
Dean

MIME-Version: 1.0
In-Reply-To: <1400767594.410886553.hpg0g9iu@frv37.fwdcdn.com>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <1400767594.410886553.hpg0g9iu@frv37.fwdcdn.com>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-19098-1449300842-1549.95865-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 680
Apologies for the delay in reviewing this patch. You referred to XML::Simple producing this output: <user login="bob" password="qwerty"> </user> And said "it stands to reason, that there should be no content at all in this case.". i.e.: <user login="bob" password="qwerty" /> Whilst I can see an argument either way, XMLin() will discard the extra whitespace so it makes no material difference. If you need that level of control over the generated XML then XML::Simple is a very poor tool for the job. Although it is a minor change, the upside is also small so I'm choosing not to accept the patch due to the potential risk of breaking downstream code. Regards Grant


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.