diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a94ecd7a..b74ee513 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -42,11 +42,17 @@ 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' + - rails: '5.2' + ruby: '3.1' + - rails: '7.0' + ruby: '2.6' + - rails: '7.0' + ruby: '2.7' runs-on: ubuntu-latest env: RAILS_VERSION: ${{ matrix.rails }} 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..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 @@ -45,10 +46,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_ical_spec.rb b/spec/examples/to_ical_spec.rb index 7ee59236..39dd5209 100644 --- a/spec/examples/to_ical_spec.rb +++ b/spec/examples/to_ical_spec.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + "/../spec_helper" +require "active_support" require "active_support/time" describe IceCube, "to_ical" do 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