summaryrefslogtreecommitdiff
path: root/Utils
diff options
context:
space:
mode:
authorcarlosg <carlosg>2006-09-08 19:02:43 +0000
committercarlosg <carlosg>2006-09-08 19:02:43 +0000
commitee7cc254ce8dfff06f4db34df989e074e7c9d3f4 (patch)
treed58782025daba6c97b534abef4f6b813df949559 /Utils
parent3283c98bed828819e0f44d5978be58066a76f6d8 (diff)
2006-09-08 Carlos Garnacho <carlosg@gnome.org>
* Utils/Parse.pm (get_from_ini) * Utils/Replace.pm (set_init) (remove_ini_section): escape properly the section name so it doesn't barf in regexps. Fixes GNOME bug #325495.
Diffstat (limited to 'Utils')
-rw-r--r--Utils/Parse.pm4
-rw-r--r--Utils/Replace.pm15
2 files changed, 12 insertions, 7 deletions
diff --git a/Utils/Parse.pm b/Utils/Parse.pm
index 52be03b..ecd6931 100644
--- a/Utils/Parse.pm
+++ b/Utils/Parse.pm
@@ -824,19 +824,21 @@ sub get_from_ini
my ($file, $section, $var) = @_;
my ($fd, $res, $line);
my $found_section_flag = 0;
+ my $escaped_section;
&Utils::Report::enter ();
&Utils::Report::do_report ("parse_ini", $var, $file, $section);
$fd = &Utils::File::open_read_from_names ($file);
&Utils::Report::leave ();
$res = undef;
+ $escaped_section = &escape ($section);
while (($line = &ini_line_read ($fd)) != -1)
{
$_ = $$line;
next if (/^$/);
- if (/\[$section\]/i)
+ if (/\[$escaped_section\]/i)
{
$found_section_flag = 1;
next;
diff --git a/Utils/Replace.pm b/Utils/Replace.pm
index 055967c..c0ad761 100644
--- a/Utils/Replace.pm
+++ b/Utils/Replace.pm
@@ -1,4 +1,3 @@
-#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# replace.pl: Common in-line replacing stuff for the ximian-setup-tools backends.
@@ -539,6 +538,7 @@ sub set_ini
my ($file, $section, $var, $value) = @_;
my ($buff, $i, $found_flag, $ret);
my ($pre_space, $post_comment, $sec_save);
+ my ($escaped_section);
&Utils::Report::enter ();
&Utils::Report::do_report ("replace_ini", $var, $section, $file);
@@ -547,6 +547,7 @@ sub set_ini
&Utils::File::join_buffer_lines ($buff);
$found_flag = 0;
+ $escaped_section = Utils::Parse::escape ($section);
foreach $i (@$buff)
{
@@ -558,9 +559,9 @@ sub set_ini
if ($i ne "")
{
- if ($i =~ /\[$section\]/i)
+ if ($i =~ /\[$escaped_section\]/i)
{
- $i =~ s/(\[$section\][ \t]*)//i;
+ $i =~ s/(\[$escaped_section\][ \t]*)//i;
$sec_save = $1;
$found_flag = 1;
}
@@ -572,7 +573,7 @@ sub set_ini
$i = "$var = $value\n$i" if ($value ne "");
$found_flag = 2;
}
-
+
if ($i =~ /^$var[ \t]*=/i)
{
if ($value ne "")
@@ -613,11 +614,13 @@ sub remove_ini_section
my ($file, $section) = @_;
my ($buff, $i, $found_flag, $ret);
my ($pre_space, $post_comment, $sec_save);
+ my ($escaped_section);
&Utils::Report::enter ();
&Utils::Report::do_report ("replace_del_ini_sect", $section, $file);
$buff = &Utils::File::load_buffer ($file);
+ $escaped_section = &Utils::Parse::escape ($section);
&Utils::File::join_buffer_lines ($buff);
$found_flag = 0;
@@ -632,9 +635,9 @@ sub remove_ini_section
if ($i ne "")
{
- if ($i =~ /\[$section\]/i)
+ if ($i =~ /\[$escaped_section\]/i)
{
- $i =~ s/(\[$section\][ \t]*)//i;
+ $i =~ s/(\[$escaped_section\][ \t]*)//i;
$found_flag = 1;
}
elsif ($found_flag && $i =~ /\[.+\]/i)