Skip to content

fix(dates): Fix validation of impossible dates #3821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged

Conversation

ivannovosad
Copy link
Contributor

Context

It was possible to call GET /api/v1/invoices API endpoint with impossible issuing_date_from, issuing_date_to params e.g.: 2025-02-30

Description

Fix the validation method: Common#valid_date?

@ivannovosad ivannovosad requested a review from Copilot June 12, 2025 08:22
Copilot

This comment was marked as outdated.

@ivannovosad ivannovosad force-pushed the fix-dates-validation branch from aa2ed09 to 3740107 Compare June 12, 2025 08:32
@ivannovosad ivannovosad requested review from Copilot and floganz June 12, 2025 08:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the validation of dates by improving the Common#valid_date? method to correctly handle impossible dates.

  • Updated the date validation logic in Common#valid_date? to catch Date::Error exceptions.
  • Enhanced test coverage in common_spec.rb to verify behavior for both valid and invalid date strings.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
spec/controllers/concerns/common_spec.rb Added tests for valid, malformed, and impossible dates.
app/controllers/concerns/common.rb Replaced Date._strptime with Date.strptime and added exception handling to improve date validation.
Comments suppressed due to low confidence (1)

app/controllers/concerns/common.rb:11

  • Consider including a format string in the Date.strptime call for clarity and to ensure consistency in date parsing (e.g., Date.strptime(date, '%Y-%m-%d')).
Date.strptime(date)

@ivannovosad ivannovosad merged commit 05471b1 into main Jun 12, 2025
14 checks passed
@ivannovosad ivannovosad deleted the fix-dates-validation branch June 12, 2025 09:00
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
## Context

It was possible to call `GET /api/v1/invoices` API endpoint with
impossible `issuing_date_from`, `issuing_date_to` params e.g.:
`2025-02-30`

## Description

Fix the validation method: `Common#valid_date?`
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.

3 participants