Skip to content

[Repo Assist] fix: defensive DateTime parsing and improve Range header error message#1699

Merged
dsyme merged 2 commits intomainfrom
repo-assist/improve-http-range-errormsg-20260317-7a9852095e26d1a0
Mar 18, 2026
Merged

[Repo Assist] fix: defensive DateTime parsing and improve Range header error message#1699
dsyme merged 2 commits intomainfrom
repo-assist/improve-http-range-errormsg-20260317-7a9852095e26d1a0

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

This PR fixes two small but genuine defensive-coding/error-reporting issues found during codebase investigation.

Changes

1. TextConversions.AsDateTime / AsDateTimeOffset — overflow safety

AsDateTime and AsDateTimeOffset both parsed the milliseconds portion of a Microsoft /Date(...)/ timestamp using Double.Parse without any bounds check. For a string like /Date(9999...9)/ with hundreds of digits, Double.Parse returns Double.PositiveInfinity, which then causes DateTime.AddMilliseconds(Infinity) to throw ArgumentOutOfRangeException — rather than returning None as callers expect from these "safe" conversion functions.

Fix: Use Double.TryParse with InvariantCulture and NumberStyles.Integer, and guard against Double.IsInfinity; wrap AddMilliseconds in a try/catch for ArgumentOutOfRangeException. The normal-range case (e.g. /Date(1577836800000)/) is unaffected.

2. Http.fs Range header error message

When the Range header value has the wrong number of --separated parts (e.g. "bytes=0-100-200"), the error was:

failwithf "Invalid value for the Range header (%O)" bytes

Here bytes is a string[], so users would see Invalid value for the Range header (System.String[]) rather than the actual invalid input. Changed to use value (the original header string) with %s.

Test Status

  • ✅ Build: succeeded (pre-existing warnings only)
  • TextConversions tests: 25/25 pass, including two new overflow-safety assertions (/Date(9...9)/None)
  • ✅ Full Core test suite: 2893 passed, 0 failed

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

- TextConversions.AsDateTime / AsDateTimeOffset: use Double.TryParse with
  InvariantCulture instead of Double.Parse, and guard against values that
  would overflow DateTime/DateTimeOffset.AddMilliseconds (e.g. a /Date(9...9)/
  string with hundreds of digits now returns None instead of throwing
  ArgumentOutOfRangeException).
- Http.fs setHeaders Range case: fix error message to show the original
  header value (the 'value' variable) instead of the internal bytes array
  representation, which printed 'System.String[]' rather than the actual
  invalid value.
- Add tests for overflow-safe ms-Date parsing in TextConversions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 18, 2026 14:01
@dsyme dsyme merged commit 64451f4 into main Mar 18, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/improve-http-range-errormsg-20260317-7a9852095e26d1a0 branch March 18, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant