neatjson 0.10.4 → 0.10.5

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
  SHA256:
3
- metadata.gz: 2e29bd247652e7a911282fd3556f0a19cdb3e1fca0f83b04892ae961e11394ea
4
- data.tar.gz: c3b4105091a863dc151e49e7d4af197f247af17eb5bdfaf9cc42c584ba76114b
3
+ metadata.gz: a57868f948eff5015d2e142f5bdc73c543e8a8710c321109eb2e1b2ca2017a87
4
+ data.tar.gz: 388c42b8860c5800293fcf8e7a2a5b64d2e327f4823390266f7916edc40c0553
5
5
  SHA512:
6
- metadata.gz: 372b882820a3ea8288c214e305254b54d1234798baa949c4a4b4f3a442d6043c488b14ff160d6323be8cc3ef12c89bac90bf8bcec2312bff40cf9e00ef9e04aa
7
- data.tar.gz: cc97ed7a14dea8224747c405213fcefefdc3866aef0a6686d73fa9c9259bf87b3c0cc573786c9ad1fcdf4652a6a045cd7554c922854390d119d49b5b7dd5bcc4
6
+ metadata.gz: 8b30fb0651981e4e4fc9c7ce6f1af90472355dc8828e51468b90b132542e13fb98e096a072775f7ebc2195e319587fa08dfd1437a35e2176413c279b68969f8c
7
+ data.tar.gz: b9093235f1b70a569d11066e0fd4602ea0bf100d0bae156cee2e764d24b32f2d05674d31c99860ee3611b75345ef4571ffe16ac3f913436c5d3ff9f9099507d2
data/README.md CHANGED
@@ -280,6 +280,9 @@ For other communication you can [email the author directly](mailto:!@phrogz.net?
280
280
 
281
281
  ## History
282
282
 
283
+ * **v0.10.5** — November 17, 2022
284
+ * Fix issue #21: Strings containing `#` get an invalid escape added (Ruby only)
285
+
283
286
  * **v0.10.4** — November 17, 2022
284
287
  * Online tool shows input/output bytes
285
288
 
data/lib/neatjson.rb CHANGED
@@ -28,7 +28,7 @@ module JSON
28
28
  # @option opts [Integer] :around_colon_1 (0) Number of spaces to put before/after colons for single-line objects.
29
29
  # @option opts [Integer] :before_colon_1 (0) Number of spaces to put before colons for single-line objects.
30
30
  # @option opts [Integer] :after_colon_1 (0) Number of spaces to put after colons for single-line objects.
31
- # @option opts [Integer] :aroun_n (0) Number of spaces to put before/after colons for multi-line objects.
31
+ # @option opts [Integer] :around_colon_n (0) Number of spaces to put before/after colons for multi-line objects.
32
32
  # @option opts [Integer] :before_colon_n (0) Number of spaces to put before colons for multi-line objects.
33
33
  # @option opts [Integer] :after_colon_n (0) Number of spaces to put after colons for multi-line objects.
34
34
  # @return [String] the JSON representation of the object.
@@ -62,8 +62,8 @@ module JSON
62
62
  memoizer = {}
63
63
  build = ->(o,indent,floats_forced) do
64
64
  memoizer[[o,indent,floats_forced]] ||= case o
65
- when String then "#{indent}#{o.inspect}"
66
- when Symbol then "#{indent}#{o.to_s.inspect}"
65
+ when String then "#{indent}#{self.generate(o)}"
66
+ when Symbol then "#{indent}#{self.generate(o.to_s)}"
67
67
  when TrueClass,FalseClass then "#{indent}#{o}"
68
68
  when NilClass then "#{indent}null"
69
69
  when Integer
@@ -119,14 +119,14 @@ module JSON
119
119
  end
120
120
  end
121
121
  keys = o.map{ |x| x.first.to_s }
122
- keyvals = o.map.with_index{ |(k,v),i| [ k.to_s.inspect, build[v, '', opts[:force_floats] || opts[:force_floats_in].include?(keys[i])] ] }
122
+ keyvals = o.map.with_index{ |(k,v),i| [ self.generate(k.to_s), build[v, '', opts[:force_floats] || opts[:force_floats_in].include?(keys[i])] ] }
123
123
  keyvals = keyvals.map{ |kv| kv.join(colon1) }.join(comma)
124
124
  one_line = "#{indent}{#{opad}#{keyvals}#{opad}}"
125
125
  if !opts[:wrap] || (one_line.length <= opts[:wrap])
126
126
  one_line
127
127
  else
128
128
  if opts[:short]
129
- keyvals = o.map{ |k,v| ["#{indent} #{opad}#{k.to_s.inspect}",v] }
129
+ keyvals = o.map{ |k,v| ["#{indent} #{opad}#{self.generate(k.to_s)}",v] }
130
130
  keyvals[0][0] = keyvals[0][0].sub "#{indent} ", "#{indent}{"
131
131
  if opts[:aligned]
132
132
  longest = keyvals.map(&:first).map(&:length).max
@@ -145,7 +145,7 @@ module JSON
145
145
  end
146
146
  "#{keyvals.join(",\n")}#{opad}}"
147
147
  else
148
- keyvals = o.map{ |k,v| ["#{indent}#{opts[:indent]}#{k.to_s.inspect}",v] }
148
+ keyvals = o.map{ |k,v| ["#{indent}#{opts[:indent]}#{self.generate(k.to_s)}",v] }
149
149
  if opts[:aligned]
150
150
  longest = keyvals.map(&:first).map(&:length).max
151
151
  formatk = "%-#{longest}s"
data/neatjson.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'date'
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "neatjson"
5
- s.version = "0.10.4"
5
+ s.version = "0.10.5"
6
6
  s.date = Date.today.iso8601
7
7
  s.authors = ["Gavin Kistner"]
8
8
  s.email = "gavin@phrogz.net"
data/test/tests.js CHANGED
@@ -34,6 +34,15 @@ exports.tests = [
34
34
 
35
35
  {value:"foo", tests:[{json:"\"foo\""}]},
36
36
  {value:"foo\nbar", tests:[{json:"\"foo\\nbar\""}]},
37
+ {value:"foo\tbar", tests:[{json:"\"foo\\tbar\""}]},
38
+ {value:"foo\rbar", tests:[{json:"\"foo\\rbar\""}]},
39
+ {value:"foo\bbar", tests:[{json:"\"foo\\bbar\""}]},
40
+ {value:"foo\fbar", tests:[{json:"\"foo\\fbar\""}]},
41
+
42
+ {value:"foo${no}bar", tests:[{json:"\"foo${no}bar\""}]},
43
+ {value:"foo\#{no}bar", tests:[{json:"\"foo\#{no}bar\""}]},
44
+ {value:"foo\\bar", tests:[{json:"\"foo\\\\bar\""}]},
45
+ {value:"foo/bar", tests:[{json:"\"foo/bar\""}]},
37
46
 
38
47
  {value:[1,2,3,4,[5,6,7,[8,9,10],11,12]], tests:[
39
48
  { json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
data/test/tests.lua CHANGED
@@ -31,9 +31,17 @@ return {
31
31
  {value=1e-9, tests={{json={'^1%.0+e%-0*9$', '^1e%-0*9$'}}}},
32
32
  {value=-2.4, tests={{json="-2", opts={decimals=0}}}},
33
33
 
34
- {value="foo", tests={{json="\"foo\""}}},
35
- -- {value= :foo, tests={{json="\"foo\""}}},
36
- {value="foo\nbar", tests={{json="\"foo\\nbar\""}}},
34
+ {value="foo", tests={{json="\"foo\""}}},
35
+ {value="foo\nbar", tests={{json="\"foo\\nbar\""}}},
36
+ {value="foo\tbar", tests={{json="\"foo\\tbar\""}}},
37
+ {value="foo\rbar", tests={{json="\"foo\\rbar\""}}},
38
+ {value="foo\bbar", tests={{json="\"foo\\bbar\""}}},
39
+ {value="foo\fbar", tests={{json="\"foo\\fbar\""}}},
40
+
41
+ {value="foo${no}bar", tests={{json="\"foo${no}bar\""}}},
42
+ {value="foo#{no}bar", tests={{json="\"foo#{no}bar\""}}},
43
+ {value="foo\\bar", tests={{json="\"foo\\\\bar\""}}},
44
+ {value="foo/bar", tests={{json="\"foo/bar\""}}},
37
45
 
38
46
  {value={1,2,3,4,{5,6,7,{8,9,10},11,12}}, tests={
39
47
  { json="[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
data/test/tests.rb CHANGED
@@ -32,6 +32,15 @@ TESTS = [
32
32
  {value:"foo", tests:[{json:"\"foo\""}]},
33
33
  {value: :foo, tests:[{json:"\"foo\""}]},
34
34
  {value:"foo\nbar", tests:[{json:"\"foo\\nbar\""}]},
35
+ {value:"foo\tbar", tests:[{json:"\"foo\\tbar\""}]},
36
+ {value:"foo\rbar", tests:[{json:"\"foo\\rbar\""}]},
37
+ {value:"foo\bbar", tests:[{json:"\"foo\\bbar\""}]},
38
+ {value:"foo\fbar", tests:[{json:"\"foo\\fbar\""}]},
39
+
40
+ {value:"foo${no}bar", tests:[{json:"\"foo${no}bar\""}]},
41
+ {value:"foo\#{no}bar", tests:[{json:"\"foo\#{no}bar\""}]},
42
+ {value:"foo\\bar", tests:[{json:"\"foo\\\\bar\""}]},
43
+ {value:"foo/bar", tests:[{json:"\"foo/bar\""}]},
35
44
 
36
45
  {value:[1,2,3,4,[5,6,7,[8,9,10],11,12]], tests:[
37
46
  { json:"[1,2,3,4,[5,6,7,[8,9,10],11,12]]" },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neatjson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Kistner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2022-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Generate JSON strings from Ruby objects with flexible formatting options.
14
14
  Key features: keep arrays and objects on a single line when they fit; format floats
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 3.2.3
53
+ rubygems_version: 3.1.6
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Pretty, powerful, flexible JSON generation.