tomlrb 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be502b2a9974d26ce6fd6b03288086b2aedbbffd
4
- data.tar.gz: 0a8e50b7800a3e6ab2f69decb26978c2013db0a6
3
+ metadata.gz: 68ff6a39fb4b176a95742a9e4ac1479b043f1a3a
4
+ data.tar.gz: f194abd1850832fd2db66c1e27e037a9c8c76e41
5
5
  SHA512:
6
- metadata.gz: 20ddd92f583df5e8eaa30359f44bcb78979b2bce0046992475db6256d15a6ff81babdc5f07841ad7f6ee8dc6466de9abb8b486ea38dd7e279fb43fb460dc826a
7
- data.tar.gz: 39f8154cbae5943b80ceedc1648ec5c95bd6bb71766aa8e836fd1be5a56bce7b69e161682f946d74d85e02539de94f19b1b3eed6089d9aee48fe40bfcd4725db
6
+ metadata.gz: 45d1317b8f190b1ad5f8d4446e3433c9c2caa36b6dfddf7798a89a7d9c7d14f6a28a257bb46cf695b23f13b762d4cfcd0e3ad8141e209a1f111a8784a13af8f6
7
+ data.tar.gz: a0b2e86ae8b3a260820895a655bdb94aa280a1de2322f4307c84bb7056e1a53af5edcd6ee42f829bb78ec91f9bc395857e4e2e2b87523c9c5c94cccdc814f5e3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 1.2.6 - 2017-10-23
2
+
3
+ * Fix issue where an unclosed table could make the parsing loop infinitely.
4
+ * Proper string escaping
5
+
1
6
  ### 1.1.3 - 2015-11-24
2
7
 
3
8
  * Bare integers can be used as keys as per the spec
data/Gemfile CHANGED
@@ -3,8 +3,7 @@ source 'https://rubygems.org'
3
3
  group :development do
4
4
  gem "bundler"
5
5
  gem "rake"
6
- gem "pry"
7
- gem "pry-byebug"
6
+ gem "byebug"
8
7
  gem "racc"
9
8
  gem "minitest"
10
9
  gem "minitest-reporters"
data/bin/console CHANGED
@@ -7,5 +7,4 @@ require "tomlrb"
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
11
- Pry.start
10
+ require "byebug"
data/lib/tomlrb.rb CHANGED
@@ -22,7 +22,7 @@ module Tomlrb
22
22
  begin
23
23
  handler = parser.parse
24
24
  rescue Racc::ParseError => e
25
- raise ParseError.new(e.message)
25
+ raise ParseError, e.message
26
26
  end
27
27
 
28
28
  handler.output
@@ -522,14 +522,14 @@ module_eval(<<'.,.,', 'parser.y', 100)
522
522
 
523
523
  module_eval(<<'.,.,', 'parser.y', 101)
524
524
  def _reduce_54(val, _values, result)
525
- result = StringUtils.replace_escaped_chars(StringUtils.strip_spaces(val[0]))
525
+ result = StringUtils.strip_spaces(val[0])
526
526
  result
527
527
  end
528
528
  .,.,
529
529
 
530
530
  module_eval(<<'.,.,', 'parser.y', 102)
531
531
  def _reduce_55(val, _values, result)
532
- result = StringUtils.strip_spaces(val[0])
532
+ result = val[0]
533
533
  result
534
534
  end
535
535
  .,.,
@@ -35,7 +35,7 @@ module Tomlrb
35
35
  @array_names << stringified_identifier
36
36
  last_identifier = identifiers.pop
37
37
  elsif @array_names.include?(stringified_identifier)
38
- raise ParseError.new('Cannot define a normal table with the same name as an already established array')
38
+ raise ParseError, 'Cannot define a normal table with the same name as an already established array'
39
39
  end
40
40
 
41
41
  yield(identifiers)
@@ -64,6 +64,7 @@ module Tomlrb
64
64
  def end_(type)
65
65
  array = []
66
66
  while (value = @stack.pop) != [type]
67
+ raise ParseError, 'Unclosed table' unless value
67
68
  array.unshift(value)
68
69
  end
69
70
  array
data/lib/tomlrb/parser.y CHANGED
@@ -99,6 +99,6 @@ rule
99
99
  string
100
100
  : STRING_MULTI { result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0])) }
101
101
  | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) }
102
- | STRING_LITERAL_MULTI { result = StringUtils.replace_escaped_chars(StringUtils.strip_spaces(val[0])) }
103
- | STRING_LITERAL { result = StringUtils.strip_spaces(val[0]) }
102
+ | STRING_LITERAL_MULTI { result = StringUtils.strip_spaces(val[0]) }
103
+ | STRING_LITERAL { result = val[0] }
104
104
  ;
@@ -1,18 +1,28 @@
1
1
  module Tomlrb
2
2
  class StringUtils
3
3
 
4
+ SPECIAL_CHARS = {
5
+ '\\t' => "\t",
6
+ '\\b' => "\b",
7
+ '\\f' => "\f",
8
+ '\\n' => "\n",
9
+ '\\r' => "\r",
10
+ '\\"' => '"',
11
+ '\\\\' => '\\'
12
+ }.freeze
13
+
4
14
  def self.multiline_replacements(str)
5
15
  strip_spaces(str).gsub(/\\\n\s+/, '')
6
16
  end
7
17
 
8
18
  def self.replace_escaped_chars(str)
9
- str
10
- .gsub(/\\n/, "\n")
11
- .gsub(/\\0/, "\0")
12
- .gsub(/\\t/, "\t")
13
- .gsub(/\\r/, "\r")
14
- .gsub(/\\\"/, '"')
15
- .gsub(/\\\\/, '\\')
19
+ str.gsub(/\\(u[\da-fA-F]{4}|U[\da-fA-F]{8}|.)/) do |m|
20
+ if m.size == 2
21
+ SPECIAL_CHARS[m] || (raise Tomlrb::ParseError.new "Escape sequence #{m} is reserved")
22
+ else
23
+ m[2..-1].to_i(16).chr(Encoding::UTF_8)
24
+ end
25
+ end
16
26
  end
17
27
 
18
28
  def self.strip_spaces(str)
@@ -1,3 +1,3 @@
1
1
  module Tomlrb
2
- VERSION = "1.2.5"
2
+ VERSION = "1.2.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomlrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francois Bernier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-22 00:00:00.000000000 Z
11
+ date: 2017-10-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A racc based toml parser
14
14
  email: