Skip Menu |

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

Report information
The Basics
Id: 68104
Status: resolved
Priority: 0/
Queue: Config-General

People
Owner: tlinden [...] cpan.org
Requestors: mgrubb [...] cpan.org
Cc:
AdminCc:

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



Subject: Single Quotes are not being stripped like double quote are
When parsing values that are surrounded by double quotes (") the parser discards the quote characters. However, the single quote is not treated the same way. The single quotes are only removed if the variable interpolation for single quotes is turned on. This behavior is inconsistent and both string quoting mechanisms should behave alike. I've attached a patch generated from git which addresses the problem.
Subject: 0001-Reconcile-treatment-of-single-and-double-quotes.patch
From: Michael Grubb <mgrubb@cpan.org> Date: Tue, 10 May 2011 21:28:40 -0500 Subject: [PATCH] Reconcile treatment of single and double quotes This patch causes Config::General to treat configuration strings surrounded by double or single quotes to be treated consistently. Without this patch strings surrounded by double quotes will have them stripped off, however single quotes are returned as part of the value. In the case of AllowSingleQuoteInterpolation being set to true, the single quotes are discarded. This patch causes the surrounding quotes to be trimmed regardless or interpolation. Signed-off-by: Michael Grubb <mgrubb@cpan.org> --- deps/Config/General.pm | 11 ++++++++--- deps/Config/General/Interpolated.pm | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/deps/Config/General.pm b/deps/Config/General.pm index c3077a6..d47a38c 100644 --- a/deps/Config/General.pm +++ b/deps/Config/General.pm @@ -791,10 +791,15 @@ sub _parse { } } - if ($value && $value =~ /^"/ && $value =~ /"$/) { - $value =~ s/^"//; # remove leading and trailing " - $value =~ s/"$//; + if ($value && $value =~ /^(['"])/ && $value =~ /$1$/) { + if ($this->{InterPolateVars} && $this->{AllowSingleQuoteInterpolation}) { + $value =~ s/(?:^["']|["']$)//g; # remove leading and trailing " + } + elsif ($this->{InterPolateVars}) { + $value =~ s/(?:^"|"$)//g; + } } + if (! defined $block) { # not inside a block @ the moment if (/^<([^\/]+?.*?)>$/) { # look if it is a block $block = $1; # store block name diff --git a/deps/Config/General/Interpolated.pm b/deps/Config/General/Interpolated.pm index e259964..860d1ff 100644 --- a/deps/Config/General/Interpolated.pm +++ b/deps/Config/General/Interpolated.pm @@ -74,7 +74,7 @@ sub _interpolate { my %quotes; if(! $this->{AllowSingleQuoteInterpolation} ) { - $value =~ s/(\'[^\']+?\')/ + $value =~ s/\'([^\']+?)\'/ my $key = "QUOTE" . ($quote_counter++) . "QUOTE"; $quotes{ $key } = $1; $key; -- 1.7.5.1
patch rejected (sorry), but this would change behavior (while perhaps inconsistent) of existing installations. However, you can use the new parameter -NormalizeValue (added in 2.51). Pass it a subroutine reference and remove the single quotes yourself.