Skip to content

Commit

Permalink
Item14237: Take care of quoted keys in legacy specs.
Browse files Browse the repository at this point in the history
Handled by _purifyKeyPath method.
  • Loading branch information
vrurg committed Apr 21, 2017
1 parent fb4b7b3 commit 21a4e8c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion core/lib/Foswiki/Config/Spec/Format/legacy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use Foswiki;
use Foswiki::Class;
extends qw(Foswiki::Object);

# We took this here because it is expected to be gone from Foswiki::Config as
# obsolete. The legacy format is to be obsoleted, this is why...
our $ITEMREGEX =
qr/(?:\{(?:'(?:\\.|[^'])+'|"(?:\\.|[^"])+"|[A-Za-z0-9_\.]+)\})+/;

has data => (
is => 'ro',
lazy => 1,
Expand Down Expand Up @@ -829,6 +834,30 @@ sub _isSectionItem {
->isa('Foswiki::Config::Spec::Format::legacy::Section');
}

# Converts key path in legacy form (which is a list of keys enclosed in curly
# braces) into an arrayref which is the new form.
sub _purifyKeyPath {
my $this = shift;
my $keyPath = shift;

my ( $h, @keyPath );

eval "\$h->$keyPath=1";

while ( ref $h ) {
my $key = ( keys %$h )[0];
Foswiki::Exception::Config::BadSpecSrc->throw(
srcFile => $this->_specFile,
secLine => $this->nextLine,
text => "Key name '$key' cannot contain a dot",
) if $key =~ /\./;
push @keyPath, $key;
$h = $h->{$key};
}

return \@keyPath;
}

sub _sectionParse {
my $this = shift;
my %params = @_;
Expand Down Expand Up @@ -927,7 +956,7 @@ m/^(?<optional>#)?\s*\$(?:(?:Fosw|TW)iki::)?cfg(?<keyPath>[^=\s]*)\s*=\s*(.*?)$/
{
my ( $keyPath, $optional ) = @+{qw(keyPath optional)};

unless ( $keyPath =~ /$Foswiki::Config::ITEMREGEX/ ) {
unless ( $keyPath =~ /$ITEMREGEX/ ) {

# XXX TODO report error here when bufferized messaging is in
# place.
Expand All @@ -936,6 +965,8 @@ m/^(?<optional>#)?\s*\$(?:(?:Fosw|TW)iki::)?cfg(?<keyPath>[^=\s]*)\s*=\s*(.*?)$/
->throw;
}

$keyPath = $this->_purifyKeyPath($keyPath);

# Push section on specs list if we're in section declaration
# now.
if ( $this->_isSectionItem($status) ) {
Expand Down

0 comments on commit 21a4e8c

Please sign in to comment.