[ruby/psych] Format Date in ISO-8601 explicitly
Fix https://github.com/ruby/psych/pull/644 https://github.com/ruby/psych/commit/b1ade765ba
This commit is contained in:
parent
5adb2591da
commit
49d49d5985
@ -189,7 +189,8 @@ module Psych
|
|||||||
end
|
end
|
||||||
|
|
||||||
def visit_Date o
|
def visit_Date o
|
||||||
register o, visit_Integer(o.gregorian)
|
formatted = format_date o
|
||||||
|
register o, @emitter.scalar(formatted, nil, nil, true, false, Nodes::Scalar::ANY)
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_DateTime o
|
def visit_DateTime o
|
||||||
@ -486,6 +487,10 @@ module Psych
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_date date
|
||||||
|
date.strftime("%Y-%m-%d")
|
||||||
|
end
|
||||||
|
|
||||||
def register target, yaml_obj
|
def register target, yaml_obj
|
||||||
@st.register target, yaml_obj
|
@st.register target, yaml_obj
|
||||||
yaml_obj
|
yaml_obj
|
||||||
|
@ -85,5 +85,20 @@ module Psych
|
|||||||
assert_match('&', yaml)
|
assert_match('&', yaml)
|
||||||
assert_match('*', yaml)
|
assert_match('*', yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_overwritten_to_s
|
||||||
|
pend "Failing on JRuby" if RUBY_PLATFORM =~ /java/
|
||||||
|
s = Psych.dump(Date.new(2023, 9, 2), permitted_classes: [Date])
|
||||||
|
assert_separately(%W[-rpsych -rdate - #{s}], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
class Date
|
||||||
|
undef to_s
|
||||||
|
def to_s; strftime("%D"); end
|
||||||
|
end
|
||||||
|
expected = ARGV.shift
|
||||||
|
begin;
|
||||||
|
s = Psych.dump(Date.new(2023, 9, 2), permitted_classes: [Date])
|
||||||
|
assert_equal(expected, s)
|
||||||
|
end;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user