Skip Menu |

This queue is for tickets about the Config-General CPAN distribution.

Report information
The Basics
Id: 104548
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Config-General

People
Owner: tlinden [...] cpan.org
Requestors: jffry [...] posteo.net
Cc:
AdminCc:

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



Subject: Invalid config file written
Date: Tue, 19 May 2015 21:12:39 +0200
To: bug-config-general [...] rt.cpan.org
From: Jeffrey Ratcliffe <jeffrey.ratcliffe [...] gmail.com>
The following code demonstrates a hash which not only does not round-trip when saved with Config::General, but also produces an invalid config file: #!/usr/bin/perl use warnings; use strict; use Config::General; my $text = "Some have not been saved.\nDo you really want to quit?"; my %hash = ( message => { $text => { switch => 1, swatch => 0 } }, other_key => 1 ); my $rc = 'test'; if ( not -r $rc ) { system "touch $rc" } my $conf = Config::General->new( -ConfigFile => $rc, ); $conf->save_file( $rc, \%hash ); my %new_hash = $conf->getall;
Well, the key $text contains a newline. Did you really expect this to work? Config::General is for configs, it's not a data serializer. The possibility to feed it with a default hash is for developers, not end users, and I wont start parsing that default hash as well. The module expects a default hash to be a valid config hash (and NOT just any hash, since it's no serializer). It is the responsibility of the developer that this hash is valid, I'd say. That being said - I could add some checks on this. But if I start with that, where shall I stop? So, in my opinion this is not a bug, but a mere usage error. - Tom
Subject: Re: [rt.cpan.org #104548] Invalid config file written
Date: Wed, 20 May 2015 17:37:45 +0200
To: bug-Config-General [...] rt.cpan.org
From: Jeffrey Ratcliffe <jeffrey.ratcliffe [...] gmail.com>
On 20 May 2015 at 08:34, T. Linden via RT <bug-Config-General@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=104548 > > Well, the key $text contains a newline. Did you really expect this to work?
Well, yes. I had assumed that the newline would be escaped somehow. Show quoted text
> Config::General is for configs, it's not a data serializer. > The possibility to feed it with a default hash is for developers, not end users, > and I wont start parsing that default hash as well. > The module expects a default hash to be a valid config hash > (and NOT just any hash, since it's no serializer). > It is the responsibility of the developer that this hash is valid, I'd say.
It would be nice if at least Config::General didn't create an invalid config file, and would instead croak. Jeff
Am Mi 20. Mai 2015, 11:37:54, RATCLIFFE schrieb: Show quoted text
> Well, yes. I had assumed that the newline would be escaped somehow.
But this would mean, that I'd need two parsers, one for textual configs and one for data structures fed in via -DefaultHash. That would be odd. Show quoted text
> It would be nice if at least Config::General didn't create an invalid > config file, and would instead croak.
I see your point. Maybe I could put some check for some chars like \n, < or > and so forth. - Tom
Ok, I added a check for this in the next version (2.57). - Tom