Skip to content

Conversation

@Matobi98
Copy link
Contributor

@Matobi98 Matobi98 commented Feb 4, 2026

Description

This PR fixes a bug in the commandArgs middleware where commands sent without arguments resulted in the first argument being the literal string "undefined".

Root Cause

The RegExp.prototype.exec() method expects a string. When no arguments were present, match[2] was undefined. JavaScript coerced this undefined value into the string "undefined", which was then matched as a valid argument by the secondary regex.

Changes

  • Updated bot/middleware/commands.ts to initialize the argument parsing string with an empty string '' if match[2] is null/undefined.

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of command argument parsing to prevent potential failures when processing arguments.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Walkthrough

A single robustness improvement in the command middleware parsing logic: the initial next_arg value now defaults to an empty string when the regex match third element is undefined, preventing potential undefined propagation through subsequent argument parsing operations.

Changes

Cohort / File(s) Summary
Argument Parsing Robustness
bot/middleware/commands.ts
Added null-coalescing fallback (match[2] || '') to ensure next_arg is always a defined string during regex-based argument extraction.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A tiny fix, so neat and small,
One empty string to catch them all,
No undefined shall slip away,
The arguments flow more safely today! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary fix: initializing next_arg with an empty string when match[2] is undefined, matching the core change in bot/middleware/commands.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator

@mostronator mostronator left a comment

Choose a reason for hiding this comment

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

LGTM ✅ Clean one-liner fix. When match[2] is undefined, the string concatenation would produce the literal string "undefined" which would then be parsed as an argument. Using || '' correctly defaults to an empty string. Good catch.

Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

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

LGTM

@grunch grunch merged commit 8abc46a into lnp2pBot:main Feb 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants