fix(server): correct early-return condition in addCustomMiddleware#1391
Closed
EdrilanBerisha wants to merge 1 commit into
Closed
fix(server): correct early-return condition in addCustomMiddleware#1391EdrilanBerisha wants to merge 1 commit into
EdrilanBerisha wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Fixes #647