Count unpaired carriage returns in adjustForLineEnding - #431
Merged
Conversation
garydgregory
added a commit
that referenced
this pull request
Aug 1, 2026
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.
adjustForLineEndingsubtracts one character for every CR and every LF it counts, but addslineEndLengthback only once per LF, so it quietly assumes every carriage return arrives paired with a line feed. I went looking after noticing the twolineEndLengthoverloads have no coverage beyond the single"12345\n\r"fixture, and an unpaired CR turns out to contribute zero to the adjusted length:maxLength("12345\r", 5, 1)returns true where the adjusted length is 6, andmaxLength("\r\r\r\r\r", 1, 2)returns true because a CR-only value adjusts to 0 no matter how long it is. A client picks its own line endings in a submitted textarea and nothing normalises them beforehand, so a field can be pushed past a declared maximum by an unbounded number of carriage returns;minLengthmirrors it and wrongly rejectsminLength("12345\r", 7, 2), whose adjusted length is exactly 7.Taking the line-ending count as the greater of the two counters rather than the LF count alone is enough, since the number of line endings is bounded below by the CR count and by the LF count. Keeping it in the private helper corrects both public overloads in one place rather than leaving each caller to normalise first, and the paired CRLF and LF-only forms compute exactly as they did, so the existing
testMaxLengthandtestMinLengthexpectations are untouched. I have deliberately left the reversed"\n\r"sequence counting as one line ending, which is what those tests pin down today; the added regression covers the unpaired carriage return only and fails without the runtime change.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.