Skip to content

fix: word count overcounts on whitespace and newlines - #148

Merged
rk234 merged 1 commit into
Hack4Impact-UMD:mainfrom
KKumar10407:fix/word-count-whitespace-leading
Jul 29, 2026
Merged

rk234 merged 1 commit into
Hack4Impact-UMD:mainfrom
KKumar10407:fix/word-count-whitespace-leading

Conversation

@KKumar10407

@KKumar10407 KKumar10407 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Variable wordCount in 'LongFormInput.tsx' was calculated with 'value.trim().split(" ")'. This is an issue as splitting on a single literal space means any consecutive space would count as another entry in the split array, unnecessarily increasing the count. Code is modified to depend on regex expressions where the split handles any length of whitespace rather than a single literal whitespace.

A test file was created and deleted to test this. The results are presented in the attached images
TestCodeUsingRegex
TestCodeResults

I appreciate you guys giving me the opportunity to fix this error and I hope it works on your end!

Sincerely,
Karthik Kumar
kkumar07@terpmail.umd.edu

Summary by CodeRabbit

  • Bug Fixes
    • Improved word counting in long-form inputs by correctly handling multiple spaces and leading or trailing whitespace.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 80a5b5e6-a9e5-42bd-bb1b-91ede0dc6654

📥 Commits

Reviewing files that changed from the base of the PR and between 456062c and 1656e5a.

📒 Files selected for processing (1)
  • frontend/src/components/form/LongFormInput.tsx

📝 Walkthrough

Walkthrough

LongFormInput now trims its value and splits on contiguous whitespace when calculating the displayed word count.

Changes

Word Count Handling

Layer / File(s) Summary
Normalize word count input
frontend/src/components/form/LongFormInput.tsx
The wordCount calculation trims leading and trailing whitespace and splits on contiguous whitespace instead of single spaces.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: lanceu0128

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing word count overcounting caused by whitespace and newlines.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes word counting in the long-form textarea by treating any run of whitespace (spaces, tabs, newlines) as a single separator, preventing overcounting when users enter multiple spaces or line breaks.

Changes:

  • Update wordCount calculation to split on \s+ instead of a single literal space.
  • Introduce an intermediate trimmedVal to ensure leading/trailing whitespace doesn’t affect the count.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rk234
rk234 merged commit f820e09 into Hack4Impact-UMD:main Jul 29, 2026
6 checks passed
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.

3 participants