Skip Menu |
 

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

Report information
The Basics
Id: 31664
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: warrenbrown.5000 [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 3.17
  • 3.18
  • 3.19
  • 3.20
  • 3.21
  • 3.22
  • 3.23
  • 3.24
  • 3.25
  • 3.26
  • 3.28
  • 3.29
  • 3.30
  • 3.31
  • 3.32
Fixed in: (no value)



Subject: keep_atts_order not working when using XML::Twig::Elt::copy
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Type: text/plain
Charset: utf8
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 528
Download (untitled) / with headers
text/plain 528b
XML::Twig-3.17 (and beyond) perl v5.6.1, v5.8.4 Element attributes are not preserving their order when using elt->copy. For me, this change mentioned below in XML::Twig::Elt::copy fixed the problem: sub copy { . . . # original code commented out # #{ my %atts= %{$atts}; # we want to do a real copy of the attributes # $copy->set_atts( \%atts); #} { my %atts; tie %atts, 'Tie::IxHash' if (keep_atts_order()); %atts = %{$atts}; # we want to do a real copy of the attributes $copy->set_atts( \%atts); } . . . }
MIME-Version: 1.0
X-Spam-Status: No, hits=-2.6 required=8.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VERIFIED,DK_SIGNED,SPF_PASS
In-Reply-To: <rt-3.6.HEAD-11458-1198009666-1931.31664-4-0 [...] rt.cpan.org>
References: <RT-Ticket-31664 [...] rt.cpan.org> <rt-3.6.HEAD-11458-1198009666-1931.31664-4-0 [...] rt.cpan.org>
Content-Type: text/plain; charset=UTF-8
X-RT-Original-Encoding: utf-8
Received: from x1.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id BC1354D814A for <bug-XML-Twig [...] rt.cpan.org>; Tue, 18 Dec 2007 16:16:13 -0500 (EST)
Received: (qmail 11287 invoked from network); 18 Dec 2007 21:16:12 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 18 Dec 2007 21:16:12 -0000
Received: from fg-out-1718.google.com (HELO fg-out-1718.google.com) (72.14.220.153) by 16.mx.develooper.com (qpsmtpd/0.40-dev) with ESMTP; Tue, 18 Dec 2007 13:16:00 -0800
Received: by fg-out-1718.google.com with SMTP id e21so379174fga.15 for <bug-XML-Twig [...] rt.cpan.org>; Tue, 18 Dec 2007 13:15:56 -0800 (PST)
Received: by 10.86.87.5 with SMTP id k5mr8115232fgb.51.1198012556689; Tue, 18 Dec 2007 13:15:56 -0800 (PST)
Received: from ?192.168.2.200? ( [217.133.3.216]) by mx.google.com with ESMTPS id l19sm12372365fgb.2007.12.18.13.15.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 18 Dec 2007 13:15:55 -0800 (PST)
Delivered-To: cpan-bug+XML-Twig [...] diesel.bestpractical.com
Subject: Re: [rt.cpan.org #31664] keep_atts_order not working when using XML::Twig::Elt::copy
User-Agent: Thunderbird 2.0.0.6 (X11/20071022)
Domainkey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=dzXXyU6DkhFQLtomNyCamSv0n8a2l5EpO5v/Z7pt6DQjBosD0a46ZawiGVAKrWnMgruRhohWKmaepFfuUlLXh2cjifyY7THMYatmiVzlBO/90WhxgzDNw+rYepa18BwWb3Ge4NoQ0vqnmW13YZ5cfHQK2Blw2frK4ebd3jvzKfk=
Return-Path: <xmltwig [...] gmail.com>
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=CbY4ETpryscmsxyvBchaRLyZ9eb7cZqCczNr1ikTEUk=; b=c7B3UoBOoN3I3WuG96Z4NxRSIaXN5SUV3jfg6gO+PM1gNXPL4QkJoBne57U/Q+gNQJ1DN0pO7TJ9HUcN0YSgbyS68qSvZtGsmZwadZpaDZJWa2Y1Wd5/M4Unf4bq/SNF8w6DqIYIMRRBbC0MVWS/dR3uTffHhDHTix5uxt0acww=
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-XML-Twig [...] rt.cpan.org
Date: Tue, 18 Dec 2007 22:17:08 +0100
X-Spam-Level: *
Message-Id: <476838D4.6030901 [...] gmail.com>
To: bug-XML-Twig [...] rt.cpan.org
Content-Transfer-Encoding: 7bit
From: mirod <xmltwig [...] gmail.com>
X-RT-Original-Encoding: utf-8
RT-Message-ID: <rt-3.6.HEAD-11458-1198012631-930.31664-0-0 [...] rt.cpan.org>
Content-Length: 611
Download (untitled) / with headers
text/plain 611b
jbubbabrown via RT wrote: Show quoted text
> Element attributes are not preserving their order when using elt->copy. > > For me, this change mentioned below in XML::Twig::Elt::copy fixed the > problem: > > sub copy { > . > . > . > # original code commented out > # > #{ my %atts= %{$atts}; # we want to do a real copy of the attributes > # $copy->set_atts( \%atts); > #} > > { my %atts; > tie %atts, 'Tie::IxHash' if (keep_atts_order()); > %atts = %{$atts}; # we want to do a real copy of the attributes > $copy->set_atts( \%atts); > }
Hi, Nice catch. I'll add this to the next release. Thanks -- mirod
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-11458-1198012631-930.31664-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Charset: utf8
References: <RT-Ticket-31664 [...] rt.cpan.org> <rt-3.6.HEAD-11458-1198009666-1931.31664-4-0 [...] rt.cpan.org> <476838D4.6030901 [...] gmail.com> <rt-3.6.HEAD-11458-1198012631-930.31664-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Message-ID: <rt-3.6.HEAD-23801-1230750675-1244.31664-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1187
Download (untitled) / with headers
text/plain 1.1k
A more succinct fix that works here is to modify the code to not do a copy, but to pass in the reference; set_atts() then copies from one IxHash to another. Here's the relevant snippet from a monkey patch that Works For Me, but I'm not sure why both copy() and set_atts() were copying the hash, could there be an overload of set_atts() that doesn't copy the hash? if( my $atts= $elt->atts) { $copy->set_atts($atts); } - Barrie On Tue Dec 18 16:17:11 2007, xmltwig@gmail.com wrote: Show quoted text
> jbubbabrown via RT wrote: > >
> > Element attributes are not preserving their order when using elt->copy. > > > > For me, this change mentioned below in XML::Twig::Elt::copy fixed the > > problem: > > > > sub copy { > > . > > . > > . > > # original code commented out > > # > > #{ my %atts= %{$atts}; # we want to do a real copy of the attributes > > # $copy->set_atts( \%atts); > > #} > > > > { my %atts; > > tie %atts, 'Tie::IxHash' if (keep_atts_order()); > > %atts = %{$atts}; # we want to do a real copy of the attributes > > $copy->set_atts( \%atts); > > }
> > Hi, > > Nice catch. I'll add this to the next release. > > Thanks >
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=DK_SIGNED,SPF_PASS
In-Reply-To: <rt-3.6.HEAD-23801-1230750675-1244.31664-5-0 [...] rt.cpan.org>
Content-Disposition: inline
References: <RT-Ticket-31664 [...] rt.cpan.org> <rt-3.6.HEAD-11458-1198009666-1931.31664-4-0 [...] rt.cpan.org> <476838D4.6030901 [...] gmail.com> <rt-3.6.HEAD-11458-1198012631-930.31664-5-0 [...] rt.cpan.org> <rt-3.6.HEAD-23801-1230750675-1244.31664-5-0 [...] rt.cpan.org>
Message-ID: <c3cb2b690901010433t7028bb05o242b9e2c0ea8f219 [...] mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
X-RT-Original-Encoding: utf-8
Received: from la.mx.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id 780654D8045 for <bug-XML-Twig [...] rt.cpan.org>; Thu, 1 Jan 2009 07:33:53 -0500 (EST)
Received: (qmail 22879 invoked by uid 103); 1 Jan 2009 12:33:52 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 1 Jan 2009 12:33:52 -0000
Received: from mail-ew0-f16.google.com (HELO mail-ew0-f16.google.com) (209.85.219.16) by 16.mx.develooper.com (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Jan 2009 04:33:50 -0800
Received: by ewy9 with SMTP id 9so5657315ewy.21 for <bug-XML-Twig [...] rt.cpan.org>; Thu, 01 Jan 2009 04:33:46 -0800 (PST)
Received: by 10.210.82.7 with SMTP id f7mr1919824ebb.115.1230813226660; Thu, 01 Jan 2009 04:33:46 -0800 (PST)
Received: by 10.210.124.15 with HTTP; Thu, 1 Jan 2009 04:33:46 -0800 (PST)
Delivered-To: cpan-bug+XML-Twig [...] diesel.bestpractical.com
Subject: Re: [rt.cpan.org #31664] keep_atts_order not working when using XML::Twig::Elt::copy
Domainkey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=YBeqQhrkkJgBCxblkq9wKXuejc4isVdUi1RBqTV50eCYyEM8M2h8hrz3R55vCR6Dtb ZtSTq1ICAZsQ7qnAtHUq/+VEur+m8qwNhBzWfpIpmEitVmcnAKMI+rrWeRI54HazTCy8 KrLfyY4FVOJv52LBCDPW10HcArtxqADzSyd5w=
Return-Path: <xmltwig [...] gmail.com>
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=HOKeYsgtksOkYK1tEpkyFs4Q6iOy58Ol6q9aQFlwczk=; b=G8Beq/jNHXhxs2RJnuOVsi8cUQ4sPdI5AHSdqCS965UAyIV8gin4Hraj9J2KSqEKX8 u3+S97bU4tQL7ju1SL2RoB/aZ1Y9mbfKEcOj0jdoKjJpoPcb/kurjyWhkOgNI0WR3s9u 4qJ68cWL2mWzkJvzvQiI4XcD5r3n0PmX1oM58=
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-XML-Twig [...] rt.cpan.org
Date: Thu, 1 Jan 2009 07:33:46 -0500
X-Spam-Level: *
To: bug-XML-Twig [...] rt.cpan.org
Content-Transfer-Encoding: 7bit
From: "Michel Rodriguez" <xmltwig [...] gmail.com>
RT-Message-ID: <rt-3.6.HEAD-23801-1230813239-862.31664-0-0 [...] rt.cpan.org>
Content-Length: 825
Download (untitled) / with headers
text/plain 825b
On Wed, Dec 31, 2008 at 2:11 PM, Barrie Slaymaker via RT <bug-XML-Twig@rt.cpan.org> wrote: Show quoted text
> A more succinct fix that works here is to modify the code to not > do a copy, but to pass in the reference; set_atts() then copies > from one IxHash to another. Here's the relevant snippet from a > monkey patch that Works For Me, but I'm not sure why both copy() > and set_atts() were copying the hash, could there be an overload of > set_atts() that doesn't copy the hash?
Thanks, I will check if this works, probably next week though. The copying of the hash in set_atts was added a while ago because I (and others IIRC) had been bitten a few times by attributes sneakily changing values when the hash pointed by the hashref was modified. So this one should stay. set_atts is not overloaded or inlined or anything. -- mirod
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-23801-1230813239-862.31664-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Charset: utf8
References: <RT-Ticket-31664 [...] rt.cpan.org> <rt-3.6.HEAD-11458-1198009666-1931.31664-4-0 [...] rt.cpan.org> <476838D4.6030901 [...] gmail.com> <rt-3.6.HEAD-11458-1198012631-930.31664-5-0 [...] rt.cpan.org> <rt-3.6.HEAD-23801-1230750675-1244.31664-5-0 [...] rt.cpan.org> <c3cb2b690901010433t7028bb05o242b9e2c0ea8f219 [...] mail.gmail.com> <rt-3.6.HEAD-23801-1230813239-862.31664-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1235991000-2264-10"
Message-ID: <rt-3.6.HEAD-2264-1235991000-1776.31664-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 685
Download (untitled) / with headers
text/plain 685b
Hello, attached a demo for the copy problem. And a .diff for Twig.pm which fixes the lost attribute order (Barries fix)and a fix for an additional problem i encountered. When I run the attached demo script i get the following output: STRING:<foo a="1" b="2" c="3">power<bar></bar></foo> PARSED:<foo a="1" b="2" c="3">power<bar></bar></foo> COPY: <foo c="3" a="1" b="2">power<bar/></foo> Not only the element order is lost, but also the empty bar element is changed to a condensed form. This isn't desired in my case, since it causes changes in the file even when the content did not change. The patch also includes a fix for this undesired changed to the short form. Regards Roland
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: multipart/mixed; boundary="----------=_1235990470-2264-8"
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="xml_twig_copy_elt.pl"
Content-Disposition: inline; filename="xml_twig_copy_elt.pl"
Content-Transfer-Encoding: base64
Content-Length: 420
use strict; use warnings; use XML::Twig; my $twig=XML::Twig->new('keep_encoding' => 1, 'keep_spaces' => 1 , 'keep_atts_order' => 1); my $string = q{<foo a="1" b="2" c="3">power<bar></bar></foo>}; my $doc = $twig->safe_parse($string); my $root = $doc->root(); my $copy = $root->copy(); print 'STRING:' , $string , "\n"; print 'PARSED:' , $root->sprint() , "\n"; print 'COPY: ' , $copy->sprint() , "\n";
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: multipart/mixed; boundary="----------=_1235991000-2264-9"
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="Twig.diff"
Content-Disposition: inline; filename="Twig.diff"
Content-Transfer-Encoding: base64
Content-Length: 416
Download Twig.diff
text/x-diff 416b
7045c7045 < if( ($elt->{'empty'} || 0)) { $copy->{empty}= 1; } # do not swap or speedup will mess up this --- > if( exists $elt->{'empty'}) { $copy->{empty}= $elt->{empty}; } 7064,7065c7064,7065 < { my %atts= %{$atts}; # we want to do a real copy of the attributes < $copy->set_atts( \%atts); --- > { > $copy->set_atts( $atts);


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

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