From d99e7f232e26785039625cb3d2b2b9f6a16c2d0b Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Thu, 24 Feb 2022 17:09:29 +0000 Subject: [PATCH 1/7] Add Ruby 3.1 and Rails 7.0 --- .github/workflows/tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a94ecd7a..46572cfe 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -42,11 +42,11 @@ jobs: - lint strategy: matrix: - rails: ['5.2', '6.0.4', '6.1'] - ruby: ['2.6', '2.7', '3.0'] + rails: ['5.2', '6.0.4', '6.1', '7.0'] + ruby: ['2.6', '2.7', '3.0', '3.1'] exclude: - rails: '5.2' - ruby: '3.0' + ruby: ['3.0', '3.1'] runs-on: ubuntu-latest env: RAILS_VERSION: ${{ matrix.rails }} From e242bce23344901323010a55e86790e01c24b694 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Thu, 24 Feb 2022 17:14:12 +0000 Subject: [PATCH 2/7] Exclude older versions of ruby from rails 7 --- .github/workflows/tests.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 46572cfe..931f10da 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -47,6 +47,8 @@ jobs: exclude: - rails: '5.2' ruby: ['3.0', '3.1'] + - rails: '7.0' + ruby: ['2.6', '2.7'] runs-on: ubuntu-latest env: RAILS_VERSION: ${{ matrix.rails }} From ba066596f991eda500489ad446a2bf7f2da5d1ae Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Thu, 24 Feb 2022 17:23:53 +0000 Subject: [PATCH 3/7] Exclude individually --- .github/workflows/tests.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 931f10da..b74ee513 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -46,9 +46,13 @@ jobs: ruby: ['2.6', '2.7', '3.0', '3.1'] exclude: - rails: '5.2' - ruby: ['3.0', '3.1'] + ruby: '3.0' + - rails: '5.2' + ruby: '3.1' + - rails: '7.0' + ruby: '2.6' - rails: '7.0' - ruby: ['2.6', '2.7'] + ruby: '2.7' runs-on: ubuntu-latest env: RAILS_VERSION: ${{ matrix.rails }} From 62a364f22ad280270a3f3aca8ae0ed4881c926c5 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Sat, 26 Feb 2022 09:26:56 +0000 Subject: [PATCH 4/7] Switch to YAML.safe_load --- lib/ice_cube/parsers/yaml_parser.rb | 2 +- lib/ice_cube/rule.rb | 2 +- spec/examples/active_support_spec.rb | 8 ++++---- spec/examples/serialization_spec.rb | 2 +- spec/examples/to_yaml_spec.rb | 14 ++++++++------ 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/ice_cube/parsers/yaml_parser.rb b/lib/ice_cube/parsers/yaml_parser.rb index 9810b797..2b979811 100644 --- a/lib/ice_cube/parsers/yaml_parser.rb +++ b/lib/ice_cube/parsers/yaml_parser.rb @@ -7,7 +7,7 @@ class YamlParser < HashParser attr_reader :hash def initialize(yaml) - @hash = YAML.load(yaml) + @hash = YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time], aliases: true) yaml.match SERIALIZED_START do |match| start_time = hash[:start_time] || hash[:start_date] TimeUtil.restore_deserialized_offset start_time, match[:tz] diff --git a/lib/ice_cube/rule.rb b/lib/ice_cube/rule.rb index 726ce17f..6652c3db 100644 --- a/lib/ice_cube/rule.rb +++ b/lib/ice_cube/rule.rb @@ -42,7 +42,7 @@ def to_yaml(*args) # From yaml def self.from_yaml(yaml) - from_hash YAML.load(yaml) + from_hash YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time]) end def to_hash diff --git a/spec/examples/active_support_spec.rb b/spec/examples/active_support_spec.rb index a07a9081..eac1798d 100644 --- a/spec/examples/active_support_spec.rb +++ b/spec/examples/active_support_spec.rb @@ -45,10 +45,10 @@ module IceCube end it "can round trip TimeWithZone to YAML" do - schedule = Schedule.new(t0 = Time.zone.parse("2010-02-05 05:00:00")) - schedule.add_recurrence_time t0 - schedule2 = Schedule.from_yaml(schedule.to_yaml) - expect(schedule.all_occurrences).to eq(schedule2.all_occurrences) + schedule1 = Schedule.new(t0 = Time.zone.parse("2010-02-05 05:00:00")) + schedule1.add_recurrence_time t0 + schedule2 = Schedule.from_yaml(schedule1.to_yaml) + expect(schedule2.all_occurrences).to eq(schedule1.all_occurrences) end it "uses local zone from start time to determine occurs_on? from the beginning of day" do diff --git a/spec/examples/serialization_spec.rb b/spec/examples/serialization_spec.rb index 7886a04a..5583c23b 100644 --- a/spec/examples/serialization_spec.rb +++ b/spec/examples/serialization_spec.rb @@ -15,7 +15,7 @@ let(:start_time) { Time.now.in_time_zone("America/Vancouver") } it "serializes time as a Hash" do - hash = YAML.load(yaml) + hash = YAML.safe_load(yaml, permitted_classes: [Symbol, Time]) expect(hash[:start_time][:time]).to eq start_time.utc expect(hash[:start_time][:zone]).to eq "America/Vancouver" end diff --git a/spec/examples/to_yaml_spec.rb b/spec/examples/to_yaml_spec.rb index f8fcade9..e7c62c59 100644 --- a/spec/examples/to_yaml_spec.rb +++ b/spec/examples/to_yaml_spec.rb @@ -78,14 +78,15 @@ module IceCube end it "should be able to make a round-trip to YAML with .day_of_year" do - schedule = Schedule.new(Time.now) - schedule.add_recurrence_rule Rule.yearly.day_of_year(100, 200) + schedule1 = Schedule.new(Time.now) + schedule1.add_recurrence_rule Rule.yearly.day_of_year(100, 200) - yaml_string = schedule.to_yaml + yaml_string = schedule1.to_yaml schedule2 = Schedule.from_yaml(yaml_string) # compare without usecs - expect(schedule.first(10).map { |r| r.to_s }).to eq(schedule2.first(10).map { |r| r.to_s }) + expect(schedule2.first(10).map { |r| r.to_s }) + .to eq(schedule1.first(10).map { |r| r.to_s }) end it "should be able to make a round-trip to YAML with .hour_of_day" do @@ -184,7 +185,7 @@ module IceCube schedule2 = Schedule.from_yaml(schedule1.to_yaml) # round trip end_time = Time.now + ONE_DAY - expect(schedule1.occurrences(end_time)).to eq(schedule2.occurrences(end_time)) + expect(schedule2.occurrences(end_time)).to eq(schedule1.occurrences(end_time)) end it "should be able to make a round trip with an exception time" do @@ -323,7 +324,8 @@ module IceCube symbol_yaml = Schedule.from_hash(symbol_data).to_yaml string_yaml = Schedule.from_hash(string_data).to_yaml - expect(YAML.load(symbol_yaml)).to eq(YAML.load(string_yaml)) + expect(YAML.safe_load(symbol_yaml, permitted_classes: [Symbol, Time])) + .to eq(YAML.safe_load(string_yaml, permitted_classes: [Symbol, Time])) end it "should raise an ArgumentError when trying to deserialize an invalid rule type" do From d238932de811bba5867b90e93cb840901e7eb1de Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Wed, 2 Mar 2022 18:13:37 +0000 Subject: [PATCH 5/7] Add time helpers --- spec/examples/to_ical_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/examples/to_ical_spec.rb b/spec/examples/to_ical_spec.rb index 7ee59236..fd85f2a2 100644 --- a/spec/examples/to_ical_spec.rb +++ b/spec/examples/to_ical_spec.rb @@ -1,5 +1,6 @@ require File.dirname(__FILE__) + "/../spec_helper" require "active_support/time" +require "active_support/testing/time_helpers" describe IceCube, "to_ical" do it "should return a proper ical representation for a basic daily rule" do From 80306d1fcb395275b221d73177f4e085bb5a1aad Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Wed, 2 Mar 2022 18:16:50 +0000 Subject: [PATCH 6/7] require active_support --- spec/examples/to_ical_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/examples/to_ical_spec.rb b/spec/examples/to_ical_spec.rb index fd85f2a2..39dd5209 100644 --- a/spec/examples/to_ical_spec.rb +++ b/spec/examples/to_ical_spec.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + "/../spec_helper" +require "active_support" require "active_support/time" -require "active_support/testing/time_helpers" describe IceCube, "to_ical" do it "should return a proper ical representation for a basic daily rule" do From 679f45962c62454a4314a4f6344026bd35acb713 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Wed, 2 Mar 2022 18:19:30 +0000 Subject: [PATCH 7/7] require active_support --- spec/examples/active_support_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/examples/active_support_spec.rb b/spec/examples/active_support_spec.rb index eac1798d..51973415 100644 --- a/spec/examples/active_support_spec.rb +++ b/spec/examples/active_support_spec.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + "/../spec_helper" +require "active_support" require "active_support/time" require "active_support/version" require "tzinfo" if ActiveSupport::VERSION::MAJOR == 3