Skip to content

[Bugfix:Forum] Fix invalid date exception#12328

Closed
SohitBennett wants to merge 11 commits into
Submitty:mainfrom
SohitBennett:fix-forum-date-bug
Closed

[Bugfix:Forum] Fix invalid date exception#12328
SohitBennett wants to merge 11 commits into
Submitty:mainfrom
SohitBennett:fix-forum-date-bug

Conversation

@SohitBennett

@SohitBennett SohitBennett commented Jan 10, 2026

Copy link
Copy Markdown

Why is this Change Important & Necessary?

Fixes #12327

Forum categories currently accept invalid date formats without proper
validation feedback. This adds server-side validation and a Cypress
end-to-end test to prevent regressions.

What is the New Behavior?

When an instructor edits a forum category date and enters an invalid
format, the server returns an error and a toast message
"Invalid date format provided." is displayed.

What steps should a reviewer take to reproduce or test the bug or new feature?

  1. Log in as instructor
  2. Navigate to the Discussion Forum
  3. Click the "More" dropdown and select "Edit Categories"
  4. Click the edit date icon on any category
  5. Enter an invalid date string (e.g., "invalid-date")
  6. Click the save button
  7. Verify the error toast "Invalid date format provided." appears

Automated Testing & Documentation

  • Added Cypress end-to-end test in forums.spec.js covering invalid date input
  • Added data-testid attributes to forum category date editing elements in ShowCategories.twig
  • No documentation changes needed on submitty.org

Other information

  • Not a breaking change
  • No migrations required
  • No security concerns

@williamjallen williamjallen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How hard would it be to add a Cypress test for this case? Assuming it isn't overly difficult, it would be great to add one so this doesn't happen again.

Comment thread site/app/controllers/forum/ForumController.php Outdated
@github-project-automation github-project-automation Bot moved this from Seeking Reviewer to Work in Progress in Submitty Development Jan 11, 2026
@codecov

codecov Bot commented Jan 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.65%. Comparing base (b70fe3d) to head (aaabe76).
⚠️ Report is 48 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12328      +/-   ##
============================================
- Coverage     21.66%   21.65%   -0.01%     
- Complexity     9639     9651      +12     
============================================
  Files           268      268              
  Lines         36226    36233       +7     
  Branches        487      487              
============================================
- Hits           7847     7846       -1     
- Misses        27896    27904       +8     
  Partials        483      483              
Flag Coverage Δ
autograder 21.32% <ø> (ø)
js 2.04% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.67% <0.00%> (-0.01%) ⬇️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SohitBennett

Copy link
Copy Markdown
Author

@williamjallen I have updated the code to catch the specific \InvalidArgumentException as requested and fixed the brace style to satisfy the linter.

I also added a regression test in site/cypress/e2e/Cypress-Feature/forums.spec.js that sends an invalid date string to the categories/edit endpoint to ensure the system handles it gracefully without crashing.

@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Jan 11, 2026
Comment thread site/cypress/e2e/Cypress-Feature/forums.spec.js Outdated
@williamjallen

Copy link
Copy Markdown
Member

@SohitBennett Please see failing CI.

@Eli-J-Schwartz

Copy link
Copy Markdown
Contributor

On the main branch, I was able to recreate the error by making a new discussion forum category, and modifying the date to be an invalid format. When that happens, the server fails to parse and returns the error message. On this branch, the error is caught, and correctly returned as JSON with status set to fail.

However, in my testing, I discovered that a number of invalid dates are parsed and return a success, despite being impossible. These include: 2026-02-29 (leap day in a non leap year), 2026-02-31 (nonexistent day in month), 2026-02-0 (day 0 in month), 2026-0-1 (month 0 in year), 0-2-1 (year far too small), 1000000-2-1 (year far too big). This is due to the DateTime constructor in PHP automatically converting invalid dates to correct ones. Since this could cause confusion for the user, I recommend using the date dropdown for new categories everywhere a user can enter a date, to limit the possible issues this could cause.

@github-actions github-actions Bot added the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Feb 16, 2026
@SohitBennett

Copy link
Copy Markdown
Author

Hi @williamjallen, I've rebased on main and addressed all the feedback from earlier. The Cypress test is included and the CI lint issues are resolved. Could you re-review when you get a chance? Also, the workflows need maintainer approval to run. Thanks!

@IDzyre

IDzyre commented Mar 26, 2026

Copy link
Copy Markdown
Member

Comment on lines +617 to +628
cy.contains('Edit Categories').click();

cy.get('.edit-category-date-button').first().click();

cy.get('.edit-category-date-input').should('be.visible').first().as('dateInput');

cy.get('@dateInput').clear({ force: true });
cy.get('@dateInput').type('invalid-date', { force: true });

cy.get('.save-date-button').first().click();

cy.contains('Invalid date format provided.').should('be.visible');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of getting ids or classes, you should add data-testid attributed wherever needed, and get those.

Comment on lines +623 to +624
cy.get('@dateInput').clear({ force: true });
cy.get('@dateInput').type('invalid-date', { force: true });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Force should be used as a last resort, is there another way to do this without forcing it ?


cy.get('.save-date-button').first().click();

cy.contains('Invalid date format provided.').should('be.visible');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you check for a specific element having that message, instead of just any element?

@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Mar 26, 2026
@SohitBennett

Copy link
Copy Markdown
Author

Hey, made the changes that were requested switched to data-testid selectors, removed the force: true, and scoped the error check to the popup-message element. Also updated the PR description. Let me know if anything else needs fixing!


it('Should handle invalid date format when editing categories', () => {
cy.get('[data-testid="more-dropdown"]').click();
cy.contains('Edit Categories').click();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a testid for this too ?

beforeEach(() => {
cy.login('instructor');
cy.visit(['sample', 'forum']);
cy.get('#nav-sidebar-collapse-sidebar').click();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a testid for this?

@bmcutler

Copy link
Copy Markdown
Member

closed due to inactivity

@bmcutler bmcutler closed this Apr 30, 2026
@github-project-automation github-project-automation Bot moved this from Work in Progress to Done in Submitty Development Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

discussion forum category date bug

5 participants