ndr_support 5.9.7 → 5.10.1

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: 219d266e0a79fb3e013249e574aa25648ddecd15b49421cd66c06780d63f47e8
4
- data.tar.gz: 48cdd5789a4aed8be6c03993eb4d1ce7ec6bf7e5225aea7e47f5e452c641d3d0
3
+ metadata.gz: '096f063918140b27d2136df336b1ce9cc749236002d62c0c3ac6ac383b5f2295'
4
+ data.tar.gz: eeb407d4d7fa47c7d803b03383da810fe7ba914569923e6f8888e580f492c208
5
5
  SHA512:
6
- metadata.gz: 869d57040385f645aae2c5b1c8dcefe5c2fd2176a7f8aa71f2859764edc7d9e0553a76065a92d29f98e3e1eb2bf29c6f8c1f0ee289e3314c90e0e105112f1cd6
7
- data.tar.gz: dc2263d789b440b4a153c086b7049b5983e512af444fbb7f469161967685bbe4e130e7a68e63e5e14e5f4e494804a049f662fbd973e6588dddbb3a6065452902
6
+ metadata.gz: 7dfffec2a85e3692e25b464ca232d1e42e4a783b5f23a6f08a3fcc0dc566ab8687b746b4fde6c206fc6f30b9e7ca674d8097b7e4b4def9928d174a19ff7fc760
7
+ data.tar.gz: 995d2de405da83acc432b42f3f551057537c648f3aded0d2f2625962a36069a9a37019c5fc6031880495a649389410534e30cc501a9b88df4cfd847001405e37
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  ## [Unreleased]
2
2
  * No unreleased changes
3
3
 
4
+ ## 5.10.1 / 2024-01-04
5
+ ## Fixed
6
+ * Add 2026 bank holidays
7
+ * Allow YAML aliases when using `yaml_safe_classes`
8
+
9
+ ## 5.10.0 / 2023-11-17
10
+ ## Changed
11
+ * Generate UTF-8 encoded YAML by default. Disable with `utf8_storage = false`
12
+ * Use `YAML.safe_load` by default. Override with
13
+ `self.yaml_safe_classes = yaml_safe_classes + [Klass1, Klass2]` and revert to
14
+ unsafe loading with `yaml_safe_classes = :unsafe` and `gem 'psych', '< 4'`
15
+
4
16
  ## 5.9.7 / 2023-11-16
5
17
  ## Fixed
6
18
  * YAMLSupport should preserve escaped backslashes in YAML text
data/code_safety.yml CHANGED
@@ -23,7 +23,7 @@ file safety:
23
23
  CHANGELOG.md:
24
24
  comments:
25
25
  reviewed_by: brian.shand
26
- safe_revision: ead7b5fe38f4f580d5c4ca2697136acc8ef1bd8b
26
+ safe_revision: c764a4d8c251b5076ed3d60391c8271bb5a099bc
27
27
  CODE_OF_CONDUCT.md:
28
28
  comments:
29
29
  reviewed_by: timgentry
@@ -71,7 +71,7 @@ file safety:
71
71
  lib/ndr_support/concerns/working_days.rb:
72
72
  comments:
73
73
  reviewed_by: brian.shand
74
- safe_revision: bac214f4c93d8753268825408fc560171fac91c0
74
+ safe_revision: 6fb8c080befbb9c741c2bc3a2fadb29fe1c3d0aa
75
75
  lib/ndr_support/date_and_time_extensions.rb:
76
76
  comments:
77
77
  reviewed_by: brian.shand
@@ -171,7 +171,7 @@ file safety:
171
171
  lib/ndr_support/version.rb:
172
172
  comments:
173
173
  reviewed_by: brian.shand
174
- safe_revision: 9a91fe5935711475449aebbb6b93bd9f40884a77
174
+ safe_revision: 3a4b0a4acb1d6dfbfc79b17ee11577cb22ab8923
175
175
  lib/ndr_support/working_days.rb:
176
176
  comments:
177
177
  reviewed_by: josh.pencheon
@@ -179,7 +179,7 @@ file safety:
179
179
  lib/ndr_support/yaml/serialization_migration.rb:
180
180
  comments:
181
181
  reviewed_by: brian.shand
182
- safe_revision: ead7b5fe38f4f580d5c4ca2697136acc8ef1bd8b
182
+ safe_revision: c764a4d8c251b5076ed3d60391c8271bb5a099bc
183
183
  ndr_support.gemspec:
184
184
  comments:
185
185
  reviewed_by: brian.shand
@@ -283,4 +283,4 @@ file safety:
283
283
  test/yaml/serialization_test.rb:
284
284
  comments:
285
285
  reviewed_by: brian.shand
286
- safe_revision: ead7b5fe38f4f580d5c4ca2697136acc8ef1bd8b
286
+ safe_revision: c764a4d8c251b5076ed3d60391c8271bb5a099bc
@@ -136,6 +136,15 @@ module WorkingDays
136
136
  '2025-08-25', # Monday - Summer bank holiday
137
137
  '2025-12-25', # Thursday - Christmas Day
138
138
  '2025-12-26', # Friday - Boxing Day
139
+ # 2026
140
+ '2026-01-01', # Thursday - New Year’s Day
141
+ '2026-04-03', # Friday - Good Friday
142
+ '2026-04-06', # Monday - Easter Monday
143
+ '2026-05-04', # Monday - Early May bank holiday
144
+ '2026-05-25', # Monday - Spring bank holiday
145
+ '2026-08-31', # Monday - Summer bank holiday
146
+ '2026-12-25', # Friday - Christmas Day
147
+ '2026-12-28', # Monday - Boxing Day
139
148
  ].map { |str| Date.parse(str) }
140
149
 
141
150
  def self.check_lookup
@@ -3,5 +3,5 @@
3
3
  # This defines the NdrSupport version. If you change it, rebuild and commit the gem.
4
4
  # Use "rake build" to build the gem, see rake -T for all bundler rake tasks.
5
5
  module NdrSupport
6
- VERSION = '5.9.7'
6
+ VERSION = '5.10.1'
7
7
  end
@@ -12,8 +12,29 @@ module NdrSupport
12
12
  # accepted by load_yaml
13
13
  YAML_SAFE_CLASSES = [Date, DateTime, Time, Symbol].freeze
14
14
 
15
+ # Set list of YAML safe classes, or :unsafe to use unsafe load
16
+ def yaml_safe_classes=(yaml_safe_classes)
17
+ @yaml_safe_classes = yaml_safe_classes
18
+ end
19
+
20
+ def yaml_safe_classes
21
+ @yaml_safe_classes || YAML_SAFE_CLASSES
22
+ end
23
+
24
+ # Allow emitted YAML to contain UTF-8 characters
25
+ # Defaults to true. (Defaulted to false in ndr_support versions < 6)
26
+ def utf8_storage=(utf8_storage)
27
+ @utf8_storage = utf8_storage
28
+ end
29
+
30
+ def utf8_storage
31
+ return @utf8_storage if @utf8_storage == false
32
+
33
+ true # New ndr_support default for versions >= 6, previously false
34
+ end
35
+
15
36
  # Wrapper around: YAML.load(string)
16
- def load_yaml(string, coerce_invalid_chars = false)
37
+ def load_yaml(string, coerce_invalid_chars = false) # rubocop:disable Style/OptionalBooleanParameter
17
38
  fix_encoding!(string, coerce_invalid_chars)
18
39
 
19
40
  # Achieve same behaviour using `syck` and `psych`:
@@ -21,10 +42,12 @@ module NdrSupport
21
42
  fix_encoding!(string, coerce_invalid_chars)
22
43
 
23
44
  # TODO: Bump NdrSupport major version, and switch to safe_load by default
24
- object = if Psych::VERSION.start_with?('3.')
45
+ object = if yaml_safe_classes == :unsafe
46
+ raise(SecurityError, 'Unsafe YAML no longer supported') unless Psych::VERSION.start_with?('3.')
47
+
25
48
  Psych.load(string)
26
49
  else
27
- Psych.safe_load(string, permitted_classes: YAML_SAFE_CLASSES)
50
+ Psych.safe_load(string, permitted_classes: yaml_safe_classes, aliases: true)
28
51
  end
29
52
 
30
53
  # Ensure that any string related to the object
@@ -37,8 +60,10 @@ module NdrSupport
37
60
 
38
61
  # Wrapper around: YAML.dump(object)
39
62
  def dump_yaml(object)
40
- # Psych produces UTF-8 encoded output; we'd rather
41
- # have YAML that can be safely stored in stores with
63
+ return Psych.dump(object) if utf8_storage
64
+
65
+ # Psych produces UTF-8 encoded output; historically we
66
+ # preferred YAML that can be safely stored in stores with
42
67
  # other encodings. If #load_yaml is used, the binary
43
68
  # encoding of the object will be reversed on load.
44
69
  Psych.dump binary_encode_any_high_ascii(object)
@@ -8,6 +8,14 @@ class SerializationTest < Minitest::Test
8
8
  assert_equal hash, load_yaml(dump_yaml(hash))
9
9
  end
10
10
 
11
+ test 'should support aliases correctly' do
12
+ x = { 'c' => 5 }
13
+ hash = { 'a' => x, 'b' => x }
14
+ hash_yaml = "---\na: &1\n c: 5\nb: *1\n"
15
+ assert_equal hash, load_yaml(hash_yaml), 'Deserialising known YAML with an alias'
16
+ assert_equal hash, load_yaml(dump_yaml(hash)), 'Deserialising a structure with repeated objects'
17
+ end
18
+
11
19
  test 'should handle syck-encoded characters' do
12
20
  assert_syck_1_8_yaml_loads_correctly
13
21
  end
@@ -44,26 +52,60 @@ class SerializationTest < Minitest::Test
44
52
  assert_yaml_coercion_behaviour
45
53
  end
46
54
 
47
- test 'dump_yaml should produce encoding-portable YAML' do
48
- original_object = { :basic => 'manana', :complex => 'mañana' }
55
+ test 'dump_yaml with utf8_storage = false should produce encoding-portable YAML' do
56
+ self.utf8_storage = false
57
+ original_object = { basic: 'manana', complex: 'mañana' }
49
58
  yaml_produced = dump_yaml(original_object)
50
59
  reloaded_object = load_yaml(yaml_produced)
51
60
 
52
- assert yaml_produced =~ /basic: manana/, 'binary-encoded more than was necessary'
61
+ assert_match(/basic: manana/, yaml_produced, 'binary-encoded more than was necessary')
53
62
 
54
63
  refute yaml_produced.bytes.detect { |byte| byte > 127 }, 'yaml has high-ascii'
55
64
  assert reloaded_object.inspect.bytes.detect { |byte| byte > 127 }
56
65
  assert_equal original_object, reloaded_object
57
66
  end
58
67
 
59
- test 'encoding-portable YAML should be loadable' do
60
- original_object = { :basic => 'manana', :complex => 'mañana' }
68
+ test 'encoding-portable YAML with utf8_storage = false should be loadable' do
69
+ self.utf8_storage = false
70
+ original_object = { basic: 'manana', complex: 'mañana' }
71
+ yaml_produced = dump_yaml(original_object)
72
+
73
+ assert_equal("---\n:basic: manana\n:complex: !binary |-\n bWHDsWFuYQ==\n", yaml_produced)
74
+
75
+ reloaded_object = load_yaml(yaml_produced)
76
+ assert_equal original_object, reloaded_object
77
+ end
78
+
79
+ test 'non-encoding-portable YAML with utf8_storage = true should be loadable' do
80
+ self.utf8_storage = true
81
+ original_object = { basic: 'manana', complex: 'mañana' }
61
82
  yaml_produced = dump_yaml(original_object)
83
+ assert_equal("---\n:basic: manana\n:complex: mañana\n", yaml_produced)
62
84
 
63
85
  reloaded_object = load_yaml(yaml_produced)
64
86
  assert_equal original_object, reloaded_object
65
87
  end
66
88
 
89
+ test 'yaml_safe_classes should filter which classes can be loaded' do
90
+ original_object = { basic: 'manana', complex: 'mañana' }
91
+ yaml_produced = dump_yaml(original_object)
92
+ self.yaml_safe_classes = []
93
+ assert_raises Psych::DisallowedClass, 'Load should fail without Symbol in yaml_safe_classes' do
94
+ load_yaml(yaml_produced)
95
+ end
96
+
97
+ self.yaml_safe_classes = [Symbol]
98
+ reloaded_object = load_yaml(yaml_produced)
99
+ assert_equal original_object, reloaded_object, 'Safe reload with Symbol class specified'
100
+
101
+ if Psych::VERSION.start_with?('3.')
102
+ # Not supported with Ruby >= 3.1 unless you force psych version < 4
103
+ self.yaml_safe_classes = :unsafe
104
+ reloaded_object = load_yaml(yaml_produced)
105
+ assert_equal original_object, reloaded_object, 'Unsafe reload with Symbol class'
106
+ end
107
+ end
108
+
67
109
  test 'time-like objects should serialise correctly with psych' do
68
110
  assert_timey_wimey_stuff
69
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndr_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.9.7
4
+ version: 5.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NCRS Development Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-16 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord