Skip to content

Commit

Permalink
Merge branch 'master' into sleep_ns_spec_on_macos
Browse files Browse the repository at this point in the history
  • Loading branch information
headius authored Nov 7, 2024
2 parents 252996c + 54c391e commit 30c8932
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/process/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative 'fixtures/common'

platform_is_not :windows do
# macOS 15 beta is not working this examples
# macOS 15 is not working this examples
return if /darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`

describe :process_daemon_keep_stdio_open_false, shared: true do
Expand Down
78 changes: 55 additions & 23 deletions core/time/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ def zone.local_to_utc(t)
Time.new("2020-12-25 00:56:17 +0900").should == t
Time.new("2020-12-25 00:57:47 +090130").should == t
Time.new("2020-12-25T00:56:17+09:00").should == t

Time.new("2020-12-25T00:56:17.123456+09:00").should == Time.utc(2020, 12, 24, 15, 56, 17, 123456)
end

it "accepts precision keyword argument and truncates specified digits of sub-second part" do
Expand All @@ -511,6 +513,16 @@ def zone.local_to_utc(t)
Time.new("2021-12-25 00:00:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 -0100"
end

it "returns Time of Jan 1 for string with just year" do
Time.new("2021").should == Time.new(2021, 1, 1)
Time.new("2021").zone.should == Time.new(2021, 1, 1).zone
Time.new("2021").utc_offset.should == Time.new(2021, 1, 1).utc_offset
end

it "returns Time of Jan 1 for string with just year in timezone specified with in keyword argument" do
Time.new("2021", in: "+17:00").to_s.should == "2021-01-01 00:00:00 +1700"
end

it "converts precision keyword argument into Integer if is not nil" do
obj = Object.new
def obj.to_int; 3; end
Expand Down Expand Up @@ -539,101 +551,109 @@ def obj.to_int; 3; end
it "raises ArgumentError if part of time string is missing" do
-> {
Time.new("2020-12-25 00:56 +09:00")
}.should raise_error(ArgumentError, "missing sec part: 00:56 ")
}.should raise_error(ArgumentError, /missing sec part: 00:56 |can't parse:/)

-> {
Time.new("2020-12-25 00 +09:00")
}.should raise_error(ArgumentError, "missing min part: 00 ")
}.should raise_error(ArgumentError, /missing min part: 00 |can't parse:/)
end

ruby_version_is "3.2.3" do
it "raises ArgumentError if the time part is missing" do
-> {
Time.new("2020-12-25")
}.should raise_error(ArgumentError, /no time information|can't parse:/)
end
end

it "raises ArgumentError if subsecond is missing after dot" do
-> {
Time.new("2020-12-25 00:56:17. +0900")
}.should raise_error(ArgumentError, "subsecond expected after dot: 00:56:17. ")
}.should raise_error(ArgumentError, /subsecond expected after dot: 00:56:17. |can't parse:/)
end

it "raises ArgumentError if String argument is not in the supported format" do
-> {
Time.new("021-12-25 00:00:00.123456 +09:00")
}.should raise_error(ArgumentError, "year must be 4 or more digits: 021")
}.should raise_error(ArgumentError, /year must be 4 or more digits: 021|can't parse:/)

-> {
Time.new("2020-012-25 00:56:17 +0900")
}.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -012-25 00:\z/)
}.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -012-25 00:\z|can't parse:/)

-> {
Time.new("2020-2-25 00:56:17 +0900")
}.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -2-25 00:56\z/)
}.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -2-25 00:56\z|can't parse:/)

-> {
Time.new("2020-12-215 00:56:17 +0900")
}.should raise_error(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 00:56:\z/)
}.should raise_error(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 00:56:\z|can't parse:/)

-> {
Time.new("2020-12-25 000:56:17 +0900")
}.should raise_error(ArgumentError, "two digits hour is expected: 000:56:17 ")
}.should raise_error(ArgumentError, /two digits hour is expected: 000:56:17 |can't parse:/)

-> {
Time.new("2020-12-25 0:56:17 +0900")
}.should raise_error(ArgumentError, "two digits hour is expected: 0:56:17 +0")
}.should raise_error(ArgumentError, /two digits hour is expected: 0:56:17 \+0|can't parse:/)

-> {
Time.new("2020-12-25 00:516:17 +0900")
}.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :516:17 \+09\z/)
}.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :516:17 \+09\z|can't parse:/)

-> {
Time.new("2020-12-25 00:6:17 +0900")
}.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :6:17 \+0900\z/)
}.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :6:17 \+0900\z|can't parse:/)

-> {
Time.new("2020-12-25 00:56:137 +0900")
}.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+0900\z/)
}.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+0900\z|can't parse:/)

-> {
Time.new("2020-12-25 00:56:7 +0900")
}.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z/)
}.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z|can't parse:/)

-> {
Time.new("2020-12-25 00:56. +0900")
}.should raise_error(ArgumentError, "fraction min is not supported: 00:56.")
}.should raise_error(ArgumentError, /fraction min is not supported: 00:56\.|can't parse:/)

-> {
Time.new("2020-12-25 00. +0900")
}.should raise_error(ArgumentError, "fraction hour is not supported: 00.")
}.should raise_error(ArgumentError, /fraction hour is not supported: 00\.|can't parse:/)
end

it "raises ArgumentError if date/time parts values are not valid" do
-> {
Time.new("2020-13-25 00:56:17 +09:00")
}.should raise_error(ArgumentError, "mon out of range")
}.should raise_error(ArgumentError, /(mon|argument) out of range/)

-> {
Time.new("2020-12-32 00:56:17 +09:00")
}.should raise_error(ArgumentError, "mday out of range")
}.should raise_error(ArgumentError, /(mday|argument) out of range/)

-> {
Time.new("2020-12-25 25:56:17 +09:00")
}.should raise_error(ArgumentError, "hour out of range")
}.should raise_error(ArgumentError, /(hour|argument) out of range/)

-> {
Time.new("2020-12-25 00:61:17 +09:00")
}.should raise_error(ArgumentError, "min out of range")
}.should raise_error(ArgumentError, /(min|argument) out of range/)

-> {
Time.new("2020-12-25 00:56:61 +09:00")
}.should raise_error(ArgumentError, "sec out of range")
}.should raise_error(ArgumentError, /(sec|argument) out of range/)

-> {
Time.new("2020-12-25 00:56:17 +23:59:60")
}.should raise_error(ArgumentError, /utc_offset/)
}.should raise_error(ArgumentError, /utc_offset|argument out of range/)

-> {
Time.new("2020-12-25 00:56:17 +24:00")
}.should raise_error(ArgumentError, /utc_offset/)
}.should raise_error(ArgumentError, /(utc_offset|argument) out of range/)

-> {
Time.new("2020-12-25 00:56:17 +23:61")
}.should raise_error(ArgumentError, /utc_offset/)
}.should raise_error(ArgumentError, /utc_offset|can't parse:/)

ruby_bug '#20797', ''...'3.4' do
-> {
Expand All @@ -647,6 +667,18 @@ def obj.to_int; 3; end
Time.new("2021-11-31 00:00:60 +09:00".encode("utf-32le"))
}.should raise_error(ArgumentError, "time string should have ASCII compatible encoding")
end

it "raises ArgumentError if string doesn't start with year" do
-> {
Time.new("a\nb")
}.should raise_error(ArgumentError, "can't parse: \"a\\nb\"")
end

it "raises ArgumentError if string has extra characters after offset" do
-> {
Time.new("2021-11-31 00:00:59 +09:00 abc")
}.should raise_error(ArgumentError, /can't parse.+ abc/)
end
end
end
end
9 changes: 8 additions & 1 deletion security/cve_2020_10663_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ def to_json(*args)

JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass
JSON(json, create_additions: true).class.should == JSONSpecs::MyClass
JSON.load(json).class.should == JSONSpecs::MyClass
if version_is(JSON::VERSION, '2.8.0')
warning = /\Wcreate_additions:\s*true\W\s+is\s+deprecated/
else
warning = ''
end
-> {
JSON.load(json).class.should == JSONSpecs::MyClass
}.should output_to_fd(warning, STDERR)

JSON.parse(json).class.should == Hash
JSON.parse(json, nil).class.should == Hash
Expand Down

0 comments on commit 30c8932

Please sign in to comment.