Conversation
| // make sure we are in bounds, truncate the rest for now | ||
| if (rowIndex + top >= board.length) { | ||
| return; | ||
| } | ||
| if (bitIndex + left >= board[0].length) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
A test should probably be added that validates a component that is larger than the board size does not increase the returned board size.
📝 WalkthroughSummary by CodeRabbitRelease Notes v1.3.4
WalkthroughThis PR introduces bounds checking to the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ❌ 2❌ Failed checks (2 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/layoutComponents.ts`:
- Around line 22-28: The code assumes board[0] exists when checking
board[0].length; add a prior guard for an empty board (if board.length === 0)
and return early before accessing board[0].length so the truncation checks using
rowIndex, top, bitIndex, and left are safe; update the existing bounds checks
around rowIndex + top and bitIndex + left to run after the empty-board guard to
avoid accessing board[0].length when board is zero-height.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 11ea29f2-97ed-462c-ba88-405ddc0fbe48
⛔ Files ignored due to path filters (2)
package-lock.jsonis excluded by!**/package-lock.jsonyarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (5)
package.jsonphp/tests/VbmlTest.phppython/tests/test_vbml.pysrc/__tests__/vbml.spec.tssrc/layoutComponents.ts
| // make sure we are in bounds, truncate the rest for now | ||
| if (rowIndex + top >= board.length) { | ||
| return; | ||
| } | ||
| if (bitIndex + left >= board[0].length) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Guard empty-board access before using board[0].length.
Line 26 still assumes board[0] exists. With a zero-height board, this can throw before truncation logic helps.
🔧 Proposed fix
export const layoutComponents = (
board: number[][],
components: number[][][],
absoluteComponents: { characters: number[][]; x: number; y: number }[],
calendarComponents?: { characters: number[][]; x: number }[]
) => {
+ const boardHeight = board.length;
+ const boardWidth = board[0]?.length ?? 0;
+ if (boardHeight === 0 || boardWidth === 0) {
+ return board;
+ }
+
let position = {
top: 0,
left: 0,
height: 0,
};
components.forEach((component) => {
// If the component size plus the currently occupied size is larger than the board width, flow to the next line
- const newLine = position.left + component[0].length > board[0].length;
+ const newLine = position.left + component[0].length > boardWidth;
const left = newLine ? 0 : position.left;
const top = newLine ? position.top + position.height : position.top;
// Fill in the individual component bits over the empty board
component.forEach((row, rowIndex) => {
row.forEach((bit, bitIndex) => {
// make sure we are in bounds, truncate the rest for now
- if (rowIndex + top >= board.length) {
+ if (rowIndex + top >= boardHeight) {
return;
}
- if (bitIndex + left >= board[0].length) {
+ if (bitIndex + left >= boardWidth) {
return;
}
board[rowIndex + top][bitIndex + left] = bit;
});
});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/layoutComponents.ts` around lines 22 - 28, The code assumes board[0]
exists when checking board[0].length; add a prior guard for an empty board (if
board.length === 0) and return early before accessing board[0].length so the
truncation checks using rowIndex, top, bitIndex, and left are safe; update the
existing bounds checks around rowIndex + top and bitIndex + left to run after
the empty-board guard to avoid accessing board[0].length when board is
zero-height.
No description provided.