-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
The word count statistic displays an incorrect value when the input contains only whitespace characters (spaces, tabs, newlines, etc.). Instead of showing 0, it shows a count of 2
File
text-statistics.vue (Line 14)
Current Behavior
When the textarea contains only whitespace:
Input: (3 spaces)
Expected word count: 0
Actual word count: 2
Root Cause
The current implementation uses
text === '' ? 0 : text.split(/\s+/).length
When text contains only whitespace, split(/\s+/) produces an array with empty strings
" ".split(/\s+/) returns ["", ""]
This results in length = 2 instead of 0
Proposed Fix
Use trim() to remove leading/trailing whitespace before checking and splitting
text.trim() === '' ? 0 : text.trim().split(/\s+/).length
What happened?
A bug happened!
System information
Browser at https://it-tools.tech/text-statistics
Where did you encounter the bug?
Public app (it-tools.tech)