Skip to content

fix: Return nil for unparseable date fields instead of raising on read - #581

Merged
razor-x merged 1 commit into
mainfrom
claude/ruby-sdk-audit-xbhaia-date-accessor
Nov 5, 2026
Merged

razor-x merged 1 commit into
mainfrom
claude/ruby-sdk-audit-xbhaia-date-accessor

Conversation

@razor-x

@razor-x razor-x commented Sep 1, 2026

Copy link
Copy Markdown
Member

Problem

SDK audit finding M10 (third part). date_accessor applied Time.parse unconditionally, so an epoch integer in any Time-typed field raised TypeError and an empty or malformed string raised ArgumentError at attribute-read time, far from the request that produced the value.

Fix

parse_datetime parses only Strings and returns nil when the string is not a date, which is what an absent date already reads as (@return [Time, nil] on optional dates). A value the API promised as a datetime but did not deliver is unusable as a Time either way; returning nil keeps the read from crashing an unrelated code path.

Tests

spec/resources/base_resource_spec.rb: missing, empty, non-date string, and epoch integer values all read as nil; a valid ISO string still parses.

Revert-check against main: 3 failures, ArgumentError twice and TypeError once from Time.parse.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SQW83gyXeUG61RDrHEky97


Generated by Claude Code

Date accessors called Time.parse on whatever the API sent, so an epoch
integer raised TypeError and an empty or malformed string raised
ArgumentError at attribute read time, far from the request that produced
the value.

Parse only strings and return nil when the string is not a date, matching
the nil an absent date already reads as.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SQW83gyXeUG61RDrHEky97
@razor-x
razor-x force-pushed the claude/ruby-sdk-audit-xbhaia-date-accessor branch from ed91e29 to 9e36bbb Compare November 5, 2026 20:01
@razor-x
razor-x merged commit 35ed10e into main Nov 5, 2026
17 checks passed
@razor-x
razor-x deleted the claude/ruby-sdk-audit-xbhaia-date-accessor branch November 5, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants