fix: use mb_strlen for multibyte characters in LineLength sniff#3971
Closed
dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
Closed
fix: use mb_strlen for multibyte characters in LineLength sniff#3971dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
Conversation
…squizlabs#3923) The Generic.Files.LineLength sniff was using strlen() to calculate comment line lengths, which counts bytes instead of characters. This caused false positives when comments contained multibyte UTF-8 characters like Norwegian letters (å, æ, ø). Changed to use mb_strlen() and mb_strrpos() with UTF-8 encoding when available, falling back to strlen() and strrpos() when the mb_* functions are not available.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
fixes #3923
changed Generic.Files.LineLength to use mb_strlen() instead of strlen() when calculating comment line lengths, so multibyte UTF-8 characters are counted correctly instead of by byte count
Changes
Test
tested with the reproduction case from the issue - Norwegian text with å, æ, ø characters now correctly reports 32 chars instead of 35 bytes