Skip to content

fix(server): correct early-return condition in addCustomMiddleware#1391

Closed
EdrilanBerisha wants to merge 1 commit into
UI5:mainfrom
EdrilanBerisha:main
Closed

fix(server): correct early-return condition in addCustomMiddleware#1391
EdrilanBerisha wants to merge 1 commit into
UI5:mainfrom
EdrilanBerisha:main

Conversation

@EdrilanBerisha
Copy link
Copy Markdown

The condition !projectCustomMiddleware.length === 0 was always false due to JavaScript operator precedence: the ! unary operator converts length to a boolean first (yielding true for an empty array), and true === 0 is always false. As a result the early-return guard never fired, so addCustomMiddleware() always iterated the array even when it was empty.

Fixed it by using the correct expression projectCustomMiddleware.length === 0.

Add two regression tests that explicitly cover:

  • an empty custom middleware array causes an early return (no calls to addMiddleware or getExtension)
  • a non-empty custom middleware array is still processed correctly

Fixes #647

The condition !projectCustomMiddleware.length === 0 was always false
due to JavaScript operator precedence: the ! unary operator converts
length to a boolean first (yielding true for an empty array), and
true === 0 is always false. As a result the early-return guard
never fired, so addCustomMiddleware() always iterated the array even
when it was empty.

Fix by using the correct expression projectCustomMiddleware.length === 0.

Add two regression tests that explicitly cover:
- an empty custom middleware array causes an early return (no calls to
  addMiddleware or getExtension)
- a non-empty custom middleware array is still processed correctly

Fixes UI5#647
RandomByte added a commit that referenced this pull request May 22, 2026
The early-return check `!projectCustomMiddleware.length === 0` parses as
`(!length) === 0`, which is always false for both empty and non-empty
arrays. The branch never fired, but the for-loop below already handles
empty arrays as a no-op, so behavior was unchanged.

Initially found by @EdrilanBerisha in
#1391
RandomByte added a commit that referenced this pull request May 22, 2026
The early-return check `!projectCustomMiddleware.length === 0` parses as
`(!length) === 0`, which is always false for both empty and non-empty
arrays. The branch never fired, but the for-loop below already handles
empty arrays as a no-op, so behavior was unchanged.

Initially found by @EdrilanBerisha in
#1391
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.

ui5 serve is very slow, can it do a pre-bundle before serving?

1 participant