Skip to content

fix: off-by-one in middleware after() and afterSend() loops#304

Merged
usernane merged 1 commit intomainfrom
dev
Apr 29, 2026
Merged

fix: off-by-one in middleware after() and afterSend() loops#304
usernane merged 1 commit intomainfrom
dev

Conversation

@usernane
Copy link
Copy Markdown
Member

Summary

Fix off-by-one error in middleware after() and afterSend() loop conditions in App::start(), which caused these methods to be skipped when only one middleware is assigned to a route.

Motivation

When a route has a single middleware, count($mdArr) - 1 = 0 and the loop condition $x > 0 evaluates to false immediately, so after() and afterSend() are never called. Fixes #299.

Changes

  • Changed loop condition from $x > 0 to $x >= 0 in the afterSend() loop (line 167)
  • Changed loop condition from $x > 0 to $x >= 0 in the after() loop (line 178)

How to Test / Verify

  • Assign a single middleware to a route and verify that after() and afterSend() are called
  • Existing test suite passes (672 tests, all non-DB tests green)

Breaking Changes and Migration Steps

None

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • The title of the pull request follows Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed)
  • I ran lint/cs-fixer (if applicable)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #299

The loop condition $x > 0 skips index 0, so when a route has only
one middleware, after() and afterSend() are never called. Changed
to $x >= 0 to include all middleware.

Fixes #299
@usernane usernane self-assigned this Apr 29, 2026
@usernane usernane merged commit ab081fb into main Apr 29, 2026
8 of 9 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.88%. Comparing base (9a039f9) to head (1faf4a1).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
WebFiori/Framework/App.php 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main     #304   +/-   ##
=========================================
  Coverage     74.88%   74.88%           
  Complexity     2974     2974           
=========================================
  Files            97       97           
  Lines          9509     9509           
=========================================
  Hits           7121     7121           
  Misses         2388     2388           
Flag Coverage Δ
php-8.1 76.20% <0.00%> (ø)
php-8.2 76.16% <0.00%> (ø)
php-8.3 74.95% <0.00%> (ø)
php-8.4 74.95% <0.00%> (ø)
php-8.5 74.86% <0.00%> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@sonarqubecloud
Copy link
Copy Markdown

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.

bug: middleware after() never called when only one middleware is assigned to a route

1 participant