You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: count whitespace runs as one word separator in chopString - #4943
Utils::chopString() splits on a single space, so a run of whitespace yields empty pieces that still count as words, and a line break is not a separator at all. An answer written as a bullet list arrives as one space-separated piece, so FaqHelper::renderAnswerPreview() hands back the whole answer instead of the 20 words the search results page asks for.
Its neighbour Utils::makeShorterText() already collapses \s+ first, and testMakeShorterTextWithMultipleSpaces() asserts that. This gives chopString() the same normalisation plus a trim(), so a leading space no longer eats a word. Single-spaced, empty and one-word input come back byte identical.
The 4.1 branch carries the same line, so please say if a backport would help.
No actionable comments were generated in the recent review.
Walkthrough
Utils::chopString now collapses consecutive whitespace and trims input before splitting. Tests cover repeated spaces, line breaks, and a multiline answer preview.
Changes: Preview text normalization
Layer / File(s)
Summary
Normalize input and verify previews phpmyfaq/src/phpMyFAQ/Utils.php, tests/phpMyFAQ/UtilsTest.php, tests/phpMyFAQ/Helper/FaqHelperTest.php
chopString collapses consecutive whitespace and trims the input before splitting. If normalization does not return a string, it trims the original input. Tests check repeated spaces, line breaks, and a three-word preview from a multiline HTML list.
This change makes answer previews count words correctly when the text has repeated spaces or line breaks. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: chopString now treats whitespace runs as one word separator. The raw summary confirms whitespace collapsing and trimming in Utils::chopString, and the objectives descr…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: chopString now treats whitespace runs as one word separator. The raw summary confirms whitespace collapsing and trimming in Utils::chopString, and the objectives describe the same fix for runs and line breaks. The title is specific and accurate, and it has a conventional fix: prefix.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 415e343f-c3ef-45ca-aeb3-01ccea451b15
Commits
Reviewing files that changed from the base of the PR and between ccdaa88 and 564bc99.
Files selected for processing: 3
phpmyfaq/src/phpMyFAQ/Utils.php
tests/phpMyFAQ/Helper/FaqHelperTest.php
tests/phpMyFAQ/UtilsTest.php
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This branch has not been deployed
No deployments
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
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.
Summary
Utils::chopString()splits on a single space, so a run of whitespace yields empty pieces that still count as words, and a line break is not a separator at all. An answer written as a bullet list arrives as one space-separated piece, soFaqHelper::renderAnswerPreview()hands back the whole answer instead of the 20 words the search results page asks for.Its neighbour
Utils::makeShorterText()already collapses\s+first, andtestMakeShorterTextWithMultipleSpaces()asserts that. This giveschopString()the same normalisation plus atrim(), so a leading space no longer eats a word. Single-spaced, empty and one-word input come back byte identical.The
4.1branch carries the same line, so please say if a backport would help.Checklist
composer checkpasses (format, lint, static analysis)composer testpasses (10568 tests, 3 redis tests skipped, no redis extension here).pnpm testnot run, no JS/TS changespnpm tscandpnpm oxlintpass for TypeScript changes - n/aphpMyFAQ\Setup\Update- n/aCHANGELOG.mdis updated for user-facing changes - n/a, a bug fix rather than a user-visible featureSummary by CodeRabbit