inifile 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/History.txt +5 -0
  2. data/lib/inifile.rb +3 -1
  3. metadata +2 -3
  4. data/a.rb +0 -125
@@ -1,3 +1,8 @@
1
+ == 2.0.1 / 2012-09-06
2
+
3
+ Bug Fixes
4
+ - Better error message for malformed INI files
5
+
1
6
  == 2.0.0 / 2012-08-29
2
7
 
3
8
  Major Enhancements
@@ -8,7 +8,7 @@ class IniFile
8
8
  include Enumerable
9
9
 
10
10
  class Error < StandardError; end
11
- VERSION = '2.0.0'
11
+ VERSION = '2.0.1'
12
12
 
13
13
  # Public: Open an INI file and load the contents.
14
14
  #
@@ -450,6 +450,8 @@ private
450
450
  # special section like a quote, newline, comment, etc.
451
451
  else
452
452
  tmp = scanner.scan_until(%r/([\n"#{@param}#{@comment}]|\\[\[\]#{@param}#{@comment}"])/m)
453
+ parse_error if tmp.nil?
454
+
453
455
  len = scanner[1].length
454
456
  tmp.slice!(tmp.length - len, len)
455
457
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inifile
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
12
+ date: 2012-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bones-git
@@ -71,7 +71,6 @@ files:
71
71
  - History.txt
72
72
  - README.md
73
73
  - Rakefile
74
- - a.rb
75
74
  - lib/inifile.rb
76
75
  - test/data/bad_1.ini
77
76
  - test/data/browscap.ini
data/a.rb DELETED
@@ -1,125 +0,0 @@
1
- require 'strscan'
2
- require 'pp'
3
-
4
- @content = <<CONTENT
5
- [section_one]
6
- one = 1
7
- two = 2
8
-
9
- [section_two] # inline section comment
10
- three = 3
11
- multi = multiline \\ # inline multiline comment
12
- support
13
- quote = "quoted # strings are the best!"
14
-
15
- ; comments should be ignored
16
- [section three]
17
- four =4
18
- five=5
19
- six =6
20
- "[foobar]" = 7
21
-
22
- [section_four]
23
- [section_five]
24
- seven and eight= 7 & 8
25
- CONTENT
26
-
27
- @comment = ';#'
28
- @param = '='
29
- @default = 'global'
30
-
31
- @ini = Hash.new {|h,k| h[k] = Hash.new}
32
-
33
- def parse
34
-
35
- string = ''
36
- property = ''
37
-
38
- @ini.clear
39
- @_line = nil
40
- @_section = nil
41
-
42
- scanner = StringScanner.new(@content)
43
- until scanner.eos?
44
-
45
- # keep track of the current line for error messages
46
- if scanner.bol?
47
- @_line = scanner.check(%r/\A.*$/) if scanner.bol?
48
- puts "[line] #@_line"
49
- end
50
-
51
- # look for escaped special characters \# \" etc
52
- if scanner.scan(%r/\\([\[\]#{@param}#{@comment}"])/)
53
- string << scanner[1]
54
-
55
- # look for quoted strings
56
- elsif scanner.scan(%r/"/)
57
- quote = scanner.scan_until(/(?:\A|[^\\])"/)
58
- parse_error('Unmatched quote') if quote.nil?
59
-
60
- quote.chomp!('"')
61
- string << quote
62
-
63
- # look for comments, empty strings, end of lines
64
- elsif scanner.skip(%r/\A\s*(?:[#{@comment}].*)?$/)
65
- string << scanner.getch unless scanner.eos?
66
-
67
- process_property(property, string)
68
-
69
- # look for the separator between property name and value
70
- elsif scanner.scan(%r/#{@param}/)
71
- if property.empty?
72
- property = string.strip
73
- string.clear
74
- else
75
- parse_error
76
- end
77
-
78
- # look for the start of a new section
79
- elsif scanner.scan(%r/\A\s*\[([^\]]+)\]/)
80
- @_section = @ini[scanner[1]]
81
-
82
- # store the next character and loop again
83
- else
84
- tmp = scanner.scan_until(%r/([\n"#{@param}#{@comment}]|\\[\[\]#{@param}#{@comment}"])/m)
85
- len = scanner[1].length
86
- tmp.slice!(tmp.length - len, len)
87
-
88
- scanner.pos = scanner.pos - len
89
- string << tmp
90
- end
91
- end
92
-
93
- process_property(property, string)
94
- end
95
-
96
- def process_property(property, value)
97
- value.chomp!
98
- return if property.empty? and value.empty?
99
- return if value.sub!(%r/\\\s*\z/, '')
100
-
101
- property.strip!
102
- value.strip!
103
-
104
- parse_error if property.empty?
105
-
106
- current_section[property.dup] = value.dup
107
-
108
- property.clear
109
- value.clear
110
-
111
- nil
112
- end
113
-
114
- def current_section
115
- @_section ||= @ini[@default]
116
- end
117
-
118
- def parse_error( msg = 'Could not parse line' )
119
- raise "#{msg}: #{@_line.inspect}"
120
- end
121
-
122
- parse
123
-
124
- puts '='*72
125
- pp @ini