dot-properties 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +5 -2
- data/README.md +6 -3
- data/dot-properties.gemspec +1 -1
- data/lib/dot_properties/version.rb +1 -1
- data/lib/dot_properties.rb +16 -7
- data/spec/dot_properties_spec.rb +17 -4
- data/spec/fixtures/sample.properties +10 -0
- metadata +25 -44
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd35e7534f70196e5b8a263cdeb5874b9e6bb394d9e623c5a1e301384f1932fa
|
4
|
+
data.tar.gz: 9077f79007f9588eb42896917bef78828a3ca536a97d28dadd33000d3c9db9c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c71ed6de04cb4db7ee34b67b64707f092e339b041ba788270b6085e0007a279966f66ff77899788027c75a913e830fca9bc69c790988414579b645fbc0aa231
|
7
|
+
data.tar.gz: ed8cb7d21c7148237b9afd497f979d1aa5b2e4558a895de98663cc68cd5398942ca0d4832f4212912de7972392b772f5f2b333b069239028ef62c0bb455318c0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Reads and writes [Java .properties files](http://en.wikipedia.org/wiki/.properti
|
|
13
13
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
|
-
gem '
|
16
|
+
gem 'dot-properties'
|
17
17
|
|
18
18
|
And then execute:
|
19
19
|
|
@@ -28,7 +28,7 @@ Or install it yourself as:
|
|
28
28
|
require 'dot_properties'
|
29
29
|
|
30
30
|
# Load a .properties file
|
31
|
-
props = DotProperties.
|
31
|
+
props = DotProperties.load('sample.properties')
|
32
32
|
|
33
33
|
# Get a value
|
34
34
|
props['foo']
|
@@ -58,9 +58,12 @@ See the spec tests and fixture data for more examples.
|
|
58
58
|
|
59
59
|
## History
|
60
60
|
|
61
|
+
- <b>0.1.4</b> - Update bundler dependency due to [CVE-2019-3881](https://github.com/advisories/GHSA-g98m-96g9-wfjq)
|
62
|
+
- <b>0.1.3</b> - Explicitly require 'forwardable' (jruby / mri2.x compat) (from @billdueber)
|
63
|
+
- <b>0.1.2</b> - Improved escaping and Unicode (\uXXXX) support
|
64
|
+
- <b>0.1.1</b> - Fix mishandled keys with leading whitespace (#1)
|
61
65
|
- <b>0.1.0</b> - Initial release
|
62
66
|
|
63
67
|
## Copyright
|
64
68
|
|
65
69
|
Copyright (c) 2013 Michael B. Klein. See LICENSE.txt for further details.
|
66
|
-
|
data/dot-properties.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.add_dependency "bundler", ">= 2.2.33"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
spec.add_development_dependency "rdoc", ">= 2.4.2"
|
data/lib/dot_properties.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "dot_properties/version"
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
4
|
class DotProperties
|
4
5
|
extend Forwardable
|
@@ -111,7 +112,7 @@ class DotProperties
|
|
111
112
|
if item[:value].nil? or item[:value].empty?
|
112
113
|
escape(item[:key])
|
113
114
|
else
|
114
|
-
"#{escape(item[:key])}#{item[:delimiter]}#{item[:value]}"
|
115
|
+
"#{escape(item[:key])}#{item[:delimiter]}#{encode(item[:value])}"
|
115
116
|
end
|
116
117
|
else
|
117
118
|
item[:value]
|
@@ -124,8 +125,8 @@ class DotProperties
|
|
124
125
|
elsif item =~ /^\s*$/
|
125
126
|
{ type: :blank, value: item }
|
126
127
|
else
|
127
|
-
key, delimiter, value = item.split /(\s*(?<!\\)[\s:=]\s*)/, 2
|
128
|
-
{ type: :value, key: unescape(key), delimiter: delimiter, value: value.to_s.gsub(/\\\n\s*/,'') }
|
128
|
+
key, delimiter, value = item.strip.split /(\s*(?<!\\)[\s:=]\s*)/, 2
|
129
|
+
{ type: :value, key: unescape(decode(key)), delimiter: delimiter, value: unescape(decode(value.to_s.gsub(/\\\n\s*/,''))) }
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
@@ -133,12 +134,20 @@ class DotProperties
|
|
133
134
|
@content.find { |item| item[:type] == :value and item[:key] == key }
|
134
135
|
end
|
135
136
|
|
136
|
-
def
|
137
|
-
|
137
|
+
def encode(v)
|
138
|
+
v.gsub(/[\r\n]/) { |m| "\\u#{'%4.4X' % m.codepoints.to_a}" }.gsub(/\\/,'\\'*3)
|
138
139
|
end
|
139
140
|
|
140
|
-
def
|
141
|
-
|
141
|
+
def decode(v)
|
142
|
+
v.gsub(/\\u([0-9A-Fa-f]{4})/) { |m| $1.hex.chr('UTF-8') }
|
143
|
+
end
|
144
|
+
|
145
|
+
def escape(v)
|
146
|
+
v.gsub(/[\s:=\\]/) { |m| "\\#{m}" }
|
147
|
+
end
|
148
|
+
|
149
|
+
def unescape(v)
|
150
|
+
v.gsub(/(?<!\\)\\/,'')
|
142
151
|
end
|
143
152
|
|
144
153
|
end
|
data/spec/dot_properties_spec.rb
CHANGED
@@ -10,15 +10,15 @@ describe DotProperties do
|
|
10
10
|
let(:propfile) { File.expand_path('../fixtures/sample.properties', __FILE__) }
|
11
11
|
subject { DotProperties.load(propfile) }
|
12
12
|
|
13
|
-
let(:properties) {
|
14
|
-
let(:comments) {
|
15
|
-
let(:blanks) {
|
13
|
+
let(:properties) { 21 }
|
14
|
+
let(:comments) { 16 }
|
15
|
+
let(:blanks) { 11 }
|
16
16
|
|
17
17
|
it { should be_an_instance_of(DotProperties) }
|
18
18
|
|
19
19
|
describe "values" do
|
20
20
|
it "should have the right number of properties" do
|
21
|
-
expect(subject.keys.length).to eq(
|
21
|
+
expect(subject.keys.length).to eq(properties)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should have the right values" do
|
@@ -32,6 +32,9 @@ describe DotProperties do
|
|
32
32
|
expect(subject['foo bar:baz= quux']).to eq('this is getting ridiculous')
|
33
33
|
expect(subject['lots of fruit']).to eq('apple, peach, kiwi, mango, banana, strawberry, raspberry')
|
34
34
|
expect(subject['some.veggies']).to eq('carrot, potato, broccoli')
|
35
|
+
expect(subject['space.key1']).to eq('space.Value1')
|
36
|
+
expect(subject['space.key2']).to eq('space.Value2')
|
37
|
+
expect(subject['space.key3']).to eq('space.Multi word value')
|
35
38
|
expect(subject['foo.empty']).to be_empty
|
36
39
|
expect(subject['bar.empty']).to be_empty
|
37
40
|
expect(subject['baz.empty']).to be_empty
|
@@ -107,6 +110,16 @@ describe DotProperties do
|
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
113
|
+
describe "content escapes" do
|
114
|
+
it "should parse Java-escaped unicode" do
|
115
|
+
expect(subject['unicode']).to eq("Command\t\u2318\nOption\t\u2325")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should unescape escaped entities" do
|
119
|
+
expect(subject['key with:several=escapes']).to eq('value with#several\escapes')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
110
123
|
describe "additional methods" do
|
111
124
|
it "#<<" do
|
112
125
|
subject << ""
|
@@ -31,12 +31,22 @@ some.veggies=carrot, \
|
|
31
31
|
potato, \
|
32
32
|
broccoli
|
33
33
|
|
34
|
+
# Leading spaces
|
35
|
+
|
36
|
+
space.key1 = space.Value1
|
37
|
+
space.key2:space.Value2
|
38
|
+
space.key3 :space.Multi word value
|
39
|
+
|
34
40
|
# Empty values
|
35
41
|
foo.empty
|
36
42
|
bar.empty=
|
37
43
|
baz.empty:
|
38
44
|
quux.empty =
|
39
45
|
|
46
|
+
# Escapes
|
47
|
+
unicode=Command\u0009\u2318\u000AOption\u0009\u2325
|
48
|
+
key\ with\:several\=es\c\apes:value\ with\#several\\escapes
|
49
|
+
|
40
50
|
# References
|
41
51
|
present = This value contains two resolvable references, ${foo.normal} and ${bar.extraspace}
|
42
52
|
missing = This value contains one resolvable reference, ${foo.normal}, and one unresolvable reference, ${quux.missing}
|
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dot-properties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael B. Klein
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-01-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
19
|
+
version: 2.2.33
|
20
|
+
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 2.2.33
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rdoc
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 2.4.2
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 2.4.2
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: simplecov
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Java-style .properties file manipulation with a light touch
|
@@ -98,8 +87,8 @@ executables: []
|
|
98
87
|
extensions: []
|
99
88
|
extra_rdoc_files: []
|
100
89
|
files:
|
101
|
-
- .gitignore
|
102
|
-
- .travis.yml
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
103
92
|
- Gemfile
|
104
93
|
- LICENSE.txt
|
105
94
|
- README.md
|
@@ -113,33 +102,25 @@ files:
|
|
113
102
|
homepage: https://github.com/mbklein/dot-properties
|
114
103
|
licenses:
|
115
104
|
- APACHE2
|
116
|
-
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
117
107
|
rdoc_options: []
|
118
108
|
require_paths:
|
119
109
|
- lib
|
120
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
111
|
requirements:
|
123
|
-
- -
|
112
|
+
- - ">="
|
124
113
|
- !ruby/object:Gem::Version
|
125
114
|
version: '0'
|
126
|
-
segments:
|
127
|
-
- 0
|
128
|
-
hash: -1306251061274732022
|
129
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
116
|
requirements:
|
132
|
-
- -
|
117
|
+
- - ">="
|
133
118
|
- !ruby/object:Gem::Version
|
134
119
|
version: '0'
|
135
|
-
segments:
|
136
|
-
- 0
|
137
|
-
hash: -1306251061274732022
|
138
120
|
requirements: []
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
specification_version: 3
|
121
|
+
rubygems_version: 3.1.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
143
124
|
summary: Read/write .properties files, respecting comments and existing formatting
|
144
125
|
as much as possible
|
145
126
|
test_files:
|