Skip Menu |

This queue is for tickets about the Geo-Gpx CPAN distribution.

Report information
The Basics
Id: 58366
Status: open
Priority: 0/
Queue: Geo-Gpx

People
Owner: Nobody in particular
Requestors: hakon [...] stordahl.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Geo::Gpx: please don't trim whitespace from cmt and desc elements
Date: Mon, 14 Jun 2010 00:00:21 +0200
To: bug-geo-gpx [...] rt.cpan.org
From: Håkon Stordahl <hakon [...] stordahl.org>
Hello. It appears that this module trims whitespace from all elements as it parses a GPX file. However, it would be nice if whitespace is preserved for at least some of the elements such as cmt and desc. For example, I sometimes like to use newlines in the comments element for the waypoints, as in the following file, test.gpx: <?xml version="1.0" encoding="utf-8"?> <gpx version="1.0"> <time>1970-01-01T00:00:00+00:00</time> <bounds maxlat="60" maxlon="60" minlat="60" minlon="60" /> <wpt lat="60" lon="60"> <ele>200</ele> <name>Test1</name> <cmt> Test1 Test2 Test3 </cmt> </wpt> </gpx> Though, running this file through Geo::Gpx gives the following output: $ perl -e 'use Geo::Gpx; open($fh, "<", "test.gpx"); $gpx = Geo::Gpx->new(input => $fh); print $gpx->xml();' <?xml version="1.0" encoding="utf-8"?> <gpx xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" creator="Geo::Gpx" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd" xmlns="http://www.topografix.com/GPX/1/0"> <time>1970-01-01T00:00:00+00:00</time> <bounds maxlat="60" maxlon="60" minlat="60" minlon="60" /> <wpt lat="60" lon="60"> <ele>200</ele> <name>Test1</name> <cmt>Test1 Test2 Test3</cmt> </wpt> </gpx> The following simple patch will ensure that whitespace is preserved for cmt and desc elements, but perhaps this should also be applied to other elements like name, for example: Index: Geo-Gpx-0.26/lib/Geo/Gpx.pm =================================================================== --- Geo-Gpx-0.26.orig/lib/Geo/Gpx.pm 2010-06-13 22:40:24.000000000 +0200 +++ Geo-Gpx-0.26/lib/Geo/Gpx.pm 2010-06-03 14:43:08.000000000 +0200 @@ -292,6 +292,10 @@ my ( $elem, $attr, $ctx ) = @_; $ctx->{$elem} = _trim( $p->text() ); }, + ['cmt', 'desct'] => sub { + my ( $elem, $attr, $ctx ) = @_; + $ctx->{$elem} = $p->text(); + }, time => sub { my ( $elem, $attr, $ctx ) = @_; my $tm = $self->_parse_time( _trim( $p->text() ) );
From: Håkon Stordahl <hakon [...] stordahl.org>
There is a slight error in the patch above (using "desct" instead of "desc" as the element name). Here's an update of the patch: Index: Geo-Gpx-0.26/lib/Geo/Gpx.pm =================================================================== --- Geo-Gpx-0.26.orig/lib/Geo/Gpx.pm 2010-06-13 22:40:24.000000000 +0200 +++ Geo-Gpx-0.26/lib/Geo/Gpx.pm 2010-06-13 23:17:46.000000000 +0200 @@ -292,6 +292,10 @@ my ( $elem, $attr, $ctx ) = @_; $ctx->{$elem} = _trim( $p->text() ); }, + ['cmt', 'desc'] => sub { + my ( $elem, $attr, $ctx ) = @_; + $ctx->{$elem} = $p->text(); + }, time => sub { my ( $elem, $attr, $ctx ) = @_; my $tm = $self->_parse_time( _trim( $p->text() ) );