mixpal 0.4.1 → 0.4.2

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: b8c9c74b1185daabd7b04ce5ac8865084eeaa8ca222c342c12ace6e4d1c444cd
4
- data.tar.gz: 82a07a359fe377bd2dbf60e95f9eb20d79afb764a4c50219846e529c981e271a
3
+ metadata.gz: 9a28fcdf5ca00ceb1a7abed59a6f90d8dcd7d7216c204ad76a87497a656dd4a7
4
+ data.tar.gz: 7c510ab982f230147a03bab655c8a7fb8da373310b817ead61fc6ea06d77f358
5
5
  SHA512:
6
- metadata.gz: 9dcceef2cf2269fc79e6c45675702ecc7e568c7340dedc62d45d358d15ff52c87a2c15d257d986bae53004d7c78a305706912f590448877d29622fc0a0f1df36
7
- data.tar.gz: a989eb95e2e2ac576379e4bcc63d161f1d8815774f8ee1a079e735a42da24ed3e7e6dbc42547a285263c4bc5c5642a660de2f5dac8881249d5b5d33bae93baa5
6
+ metadata.gz: fd6c7aa7a15bdec83398610de7431f0d185f9650522a614204b7bb63bcaa7470147faa7ed301f3cbd9c5967164ab2d92ebaa90a5b8e4445947e2073864261f72
7
+ data.tar.gz: ec9c80f83fe4b8e20735c61c359306d68dbf0a60b7d9ba74515dcb60be7d7f5f237ab14a1d1e7951e75280158ea8c78f42f886c497decc5416159b04713533fa
data/lib/mixpal/util.rb CHANGED
@@ -5,12 +5,22 @@ module Mixpal
5
5
  hash.reject! { |_, v| v.nil? }
6
6
 
7
7
  contents = hash.map do |k, v|
8
- js_value = v.is_a?(String) || v.is_a?(Time) ? "\"#{v}\"" : v
9
- "\"#{k}\": #{js_value}"
8
+ "\"#{k}\": #{escape_js_object_value(v)}"
10
9
  end.join(',').html_safe
11
10
 
12
11
  "{#{contents}}"
13
12
  end
13
+
14
+ def escape_js_object_value(value)
15
+ case value
16
+ when String
17
+ value.dump
18
+ when Time
19
+ "\"#{value}\""
20
+ else
21
+ value
22
+ end
23
+ end
14
24
  end
15
25
  end
16
26
  end
@@ -1,3 +1,3 @@
1
1
  module Mixpal
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -24,5 +24,10 @@ describe Mixpal::Util do
24
24
  expect(subject.hash_to_js_object_string(age: 21, gender: nil))
25
25
  .to eq '{"age": 21}'
26
26
  end
27
+
28
+ it 'escapes double quotes in values' do
29
+ expect(subject.hash_to_js_object_string(key: 'value "with" quotes'))
30
+ .to eq '{"key": "value \"with\" quotes"}'
31
+ end
27
32
  end
28
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - patbenatar
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-03 00:00:00.000000000 Z
12
+ date: 2023-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler