toml-rb 0.3.9 → 0.3.10

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: 53c8bc0a9cbb23e1d7f74b114ccb9b562ddc5925
4
- data.tar.gz: 6e1545aca165045cb3fbf22221c0779765335724
3
+ metadata.gz: c08aa29a171d7d63f32f49b003ba684889066e10
4
+ data.tar.gz: 6e691196c2fbf7f76d84bd9e3d9c4f404dc4b44b
5
5
  SHA512:
6
- metadata.gz: fe091042c32d0c1bcfab2750711822e3914bc1d35b4a45a2cb28f7bd8ea64d4e86b589e6000c8f31299256138dcd209c74ecfa6e5b9ade7698051bb31b4fae09
7
- data.tar.gz: 94c3033f5fc157f236d7586306e2b7d6e1d33ab38133651cfbf9ef78ac8e58afd02c98636f3702252e26df7e6d06e147037d49c53fbf6e6b0e9dc089d2b2e202
6
+ metadata.gz: afc71aad3baf66c57e2e5edb067a3bf03855a35abb9f983e6b1300d3d7ca1ebfdcdb7fce5a82fc04067300ee84f1b7b9563832bc98ff9d97a9156ce5a6bd921a
7
+ data.tar.gz: 7e779c92833849403f5b805883126611212d43582a9e852395254eb99d78831d1d5cae33d4485eb1faf8f62ea0306fe85bb77000f176833835cfabdfdff96130
data/README.md CHANGED
@@ -6,7 +6,7 @@ toml-rb
6
6
  [![Code Climate](https://codeclimate.com/github/emancu/toml-rb/badges/gpa.svg)](https://codeclimate.com/github/emancu/toml-rb)
7
7
  [![Dependency Status](https://gemnasium.com/emancu/toml-rb.svg)](https://gemnasium.com/emancu/toml-rb)
8
8
 
9
- A [TOML](https://github.com/mojombo/toml) parser using [Citrus](http://mjackson.github.io/citrus) library.
9
+ A [TOML](https://github.com/toml-lang/toml) parser using [Citrus](http://mjackson.github.io/citrus) library.
10
10
 
11
11
  TOML specs supported: `0.4.0`
12
12
 
@@ -10,7 +10,7 @@ module TOML
10
10
  attr_accessor :key
11
11
 
12
12
  def initialize(key)
13
- self.key = key
13
+ @key = key
14
14
  super "Key #{key.inspect} is defined more than once"
15
15
  end
16
16
  end
@@ -1,6 +1,17 @@
1
1
  module TOML
2
2
  # Used in primitive.citrus
3
3
  module BasicString
4
+ SPECIAL_CHARS = {
5
+ '\\0' => "\0",
6
+ '\\t' => "\t",
7
+ '\\b' => "\b",
8
+ '\\f' => "\f",
9
+ '\\n' => "\n",
10
+ '\\r' => "\r",
11
+ '\\"' => '"',
12
+ '\\\\' => '\\'
13
+ }.freeze
14
+
4
15
  def value
5
16
  aux = TOML::BasicString.transform_escaped_chars first.value
6
17
 
@@ -10,26 +21,21 @@ module TOML
10
21
  # Replace the unicode escaped characters with the corresponding character
11
22
  # e.g. \u03B4 => ?
12
23
  def self.decode_unicode(str)
13
- str.gsub(/([^\\](?:\\\\)*\\u[\da-f]{4})/i) do |m|
14
- m[0...-6] + [m[-4..-1].to_i(16)].pack('U')
15
- end
24
+ [str[2..-1].to_i(16)].pack('U')
16
25
  end
17
26
 
18
- # Replace special characters such as line feed and tabs.
19
- def self.decode_special_char(str)
20
- str.gsub(/\\0/, "\0")
21
- .gsub(/\\t/, "\t")
22
- .gsub(/\\b/, "\b")
23
- .gsub(/\\f/, "\f")
24
- .gsub(/\\n/, "\n")
25
- .gsub(/\\\"/, '"')
26
- .gsub(/\\r/, "\r")
27
+ def self.transform_escaped_chars(str)
28
+ str.gsub(/\\(u[\da-fA-F]{4}|U[\da-fA-F]{8}|.)/) do |m|
29
+ if m.size == 2
30
+ SPECIAL_CHARS[m] || parse_error(m)
31
+ else
32
+ decode_unicode(m).force_encoding('UTF-8')
33
+ end
34
+ end
27
35
  end
28
36
 
29
- def self.transform_escaped_chars(str)
30
- str = decode_special_char(str)
31
- str = decode_unicode(str)
32
- str.gsub(/\\\\/, '\\').encode('utf-8')
37
+ def self.parse_error(m)
38
+ fail ParseError.new "Escape sequence #{m} is reserved"
33
39
  end
34
40
  end
35
41
 
@@ -79,8 +79,8 @@ class GrammarTest < Minitest::Test
79
79
  match = TOML::Document.parse('"\0 \" \t \n \r"', root: :string)
80
80
  assert_equal("\0 \" \t \n \r", match.value)
81
81
 
82
- match = TOML::Document.parse('"C:\\Documents\\virus.exe"', root: :string)
83
- assert_equal('C:\\Documents\\virus.exe', match.value)
82
+ match = TOML::Document.parse('"C:\\\\Documents\\\\nada.exe"', root: :string)
83
+ assert_equal('C:\\Documents\\nada.exe', match.value)
84
84
  end
85
85
 
86
86
  def test_bool
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.3.9'
3
+ s.version = '0.3.10'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = 'TOML parser in ruby, for ruby.'
6
6
  s.description = 'A TOML parser using Citrus parsing library. '
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Mancuso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-28 00:00:00.000000000 Z
12
+ date: 2016-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus