toml-rb 4.2.0 → 4.2.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.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/toml-rb/dumper.rb +35 -8
- data/lib/toml-rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d198202b34da88436ce3d0e3cb8841bc1a6ff433a0d9397303c0870c6fed1d5
|
|
4
|
+
data.tar.gz: 916c15730aebc6974a1e7fd04e7c793a3b1321312657f370cae8c9c0a63e6f54
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: acf22dc79ffa1f4b4650e1979eaf7b3d3a04bc894c68e752008e87dbdf695d5ab4ad2c4e835b8d7a5b0aab151c802cd6cfc403ecd361a2cad125c32cf2cb42b3
|
|
7
|
+
data.tar.gz: 1bdedac516138288dcb97ce4cf59153d03d5fdc8f48a93eca7afbd3ab2931f9ca1dd73eb104decca1e1a6bc7dbc3771d575cfe6a81429e3590e3f41d4048c959
|
data/README.md
CHANGED
|
@@ -68,6 +68,22 @@ TomlRB.dump(hash)
|
|
|
68
68
|
# => "title = \"wow!\"\n[awesome]\nothers = false\nyou = true\n"
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
Conformance
|
|
72
|
+
-----------
|
|
73
|
+
|
|
74
|
+
`toml-rb` is exercised against the official
|
|
75
|
+
[toml-test](https://github.com/toml-lang/toml-test) conformance suite for both
|
|
76
|
+
TOML 1.0.0 and TOML 1.1.0. The harness lives in:
|
|
77
|
+
|
|
78
|
+
- `tool/toml-test-decoder` — toml-test decoder shim.
|
|
79
|
+
- `.github/workflows/conformance.yml` — CI workflow (per-version matrix).
|
|
80
|
+
- `.github/toml-test-skip-1.0.txt` and `.github/toml-test-skip-1.1.txt` —
|
|
81
|
+
skip-lists of currently-failing tests.
|
|
82
|
+
|
|
83
|
+
The skip-lists are a living gap report: every entry is a known limitation in
|
|
84
|
+
the current parser. The goal for v5.0.0 is **empty skip-lists** — full
|
|
85
|
+
conformance against both spec versions.
|
|
86
|
+
|
|
71
87
|
Contributing
|
|
72
88
|
------------
|
|
73
89
|
|
data/lib/toml-rb/dumper.rb
CHANGED
|
@@ -4,6 +4,18 @@ require "date"
|
|
|
4
4
|
|
|
5
5
|
module TomlRB
|
|
6
6
|
class Dumper
|
|
7
|
+
# TOML basic strings only allow these short escapes; every other control
|
|
8
|
+
# character must be written as \uXXXX (TOML 1.0.0 spec).
|
|
9
|
+
BASIC_ESCAPES = {
|
|
10
|
+
"\\" => "\\\\",
|
|
11
|
+
"\"" => "\\\"",
|
|
12
|
+
"\b" => "\\b",
|
|
13
|
+
"\t" => "\\t",
|
|
14
|
+
"\n" => "\\n",
|
|
15
|
+
"\f" => "\\f",
|
|
16
|
+
"\r" => "\\r"
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
7
19
|
attr_reader :toml_str
|
|
8
20
|
|
|
9
21
|
def initialize(hash)
|
|
@@ -96,25 +108,40 @@ module TomlRB
|
|
|
96
108
|
elsif obj.is_a?(Regexp)
|
|
97
109
|
obj.inspect.inspect
|
|
98
110
|
elsif obj.is_a?(String)
|
|
99
|
-
obj
|
|
111
|
+
escape_string(obj)
|
|
100
112
|
elsif obj.is_a?(Array)
|
|
101
113
|
"[" + obj.map(&method(:to_toml)).join(", ") + "]"
|
|
114
|
+
elsif obj.is_a?(Float) && (obj.nan? || obj.infinite?)
|
|
115
|
+
# Ruby renders these as Infinity/-Infinity/NaN, which are invalid TOML.
|
|
116
|
+
if obj.nan?
|
|
117
|
+
"nan"
|
|
118
|
+
elsif obj.negative?
|
|
119
|
+
"-inf"
|
|
120
|
+
else
|
|
121
|
+
"inf"
|
|
122
|
+
end
|
|
102
123
|
else
|
|
103
124
|
obj.inspect
|
|
104
125
|
end
|
|
105
126
|
end
|
|
106
127
|
|
|
107
128
|
def bare_key?(key)
|
|
108
|
-
!!key.to_s.match(
|
|
129
|
+
!!key.to_s.match(/\A[a-zA-Z0-9_-]+\z/)
|
|
109
130
|
end
|
|
110
131
|
|
|
111
|
-
#
|
|
112
|
-
# Ruby representation of literals or strings, mixed with special characters
|
|
113
|
-
# made the concatenation error-prone, luckiley the `#inspect` method returns
|
|
114
|
-
# exactly what we need. I decided to keep the method `quote_key/1`
|
|
115
|
-
# for readability.
|
|
132
|
+
# Quote and escape a key as a TOML basic string.
|
|
116
133
|
def quote_key(key)
|
|
117
|
-
key.
|
|
134
|
+
escape_string(key.to_s)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Serialize a Ruby string as a TOML basic string. Ruby's String#inspect
|
|
138
|
+
# emits \a \v \e for 0x07/0x0B/0x1B, which TOML (and this parser) reject.
|
|
139
|
+
def escape_string(str)
|
|
140
|
+
escaped = str.gsub(/[\x00-\x1f\x7f"\\]/) do |char|
|
|
141
|
+
BASIC_ESCAPES[char] || format('\\u%04X', char.ord)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
"\"#{escaped}\""
|
|
118
145
|
end
|
|
119
146
|
end
|
|
120
147
|
end
|
data/lib/toml-rb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: toml-rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.2.
|
|
4
|
+
version: 4.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emiliano Mancuso
|
|
8
8
|
- Lucas Tolchinsky
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: citrus
|