From d2c1e07e8088fb2372d258cfdd27ee4aab10cef1 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 14 Aug 2012 13:38:08 +0100 Subject: Fixed regex to match sections and settings with non alphanumeric characters. Fixed writing to file without any sections at all. Fixed exists checking for variable type by always casting to string and added all the tests for the above items. --- lib/puppet/provider/ini_setting/ruby.rb | 2 +- lib/puppet/util/ini_file.rb | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/ini_setting/ruby.rb b/lib/puppet/provider/ini_setting/ruby.rb index f04af06..9f13dff 100644 --- a/lib/puppet/provider/ini_setting/ruby.rb +++ b/lib/puppet/provider/ini_setting/ruby.rb @@ -2,7 +2,7 @@ require File.expand_path('../../../util/ini_file', __FILE__) Puppet::Type.type(:ini_setting).provide(:ruby) do def exists? - ini_file.get_value(resource[:section], resource[:setting]) == resource[:value] + ini_file.get_value(resource[:section], resource[:setting]) == resource[:value].to_s end def create diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 51dfda7..0505462 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -5,14 +5,13 @@ module Puppet module Util class IniFile - SECTION_REGEX = /^\s*\[([\w\d\.]+)\]\s*$/ - SETTING_REGEX = /^\s*([\w\d\.]+)\s*=\s*([\w\d\.]+)\s*$/ + SECTION_REGEX = /^\s*\[([\S.]+)\]\s*$/ + SETTING_REGEX = /^\s*([\S]+)\s*=\s*([\S]+)\s*$/ def initialize(path) @path = path @section_names = [] @sections_hash = {} - parse_file end @@ -43,7 +42,8 @@ module Util def save File.open(@path, 'w') do |fh| first_section = @sections_hash[@section_names[0]] - (0..first_section.start_line - 1).each do |line_num| + first_section.start_line == nil ? start_line = 0 : start_line = first_section.start_line + (0..start_line - 1).each do |line_num| fh.puts(lines[line_num]) end @@ -93,7 +93,6 @@ module Util elsif (match = SETTING_REGEX.match(line)) settings[match[1]] = match[2] end - line_iter.next end end @@ -129,4 +128,4 @@ module Util end end -end +end \ No newline at end of file -- cgit v1.2.3