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