fix: stop Document.getPlainText repeating content past document length - #2752
Open
Yusufihsangorgel wants to merge 2 commits into
Open
fix: stop Document.getPlainText repeating content past document length#2752Yusufihsangorgel wants to merge 2 commits into
Yusufihsangorgel wants to merge 2 commits into
Conversation
Closes singerdmx#2704. Line._getPlainText wrapped its body in while (len0 > 0), but the body already walks the whole reachable document (inner loop over this line's leaves, nextLine recursion over following lines). When the document was shorter than len, the outer loop re-processed the same nodes and repeated the content. Make it a single pass. Verified on the v11.5.0 tag (this method byte-identical): repro fails before, passes after; document suite green.
Place the singerdmx#2704 entry under the ### Fixed subsection in the repo's keep-a-changelog prose style, instead of a bare bullet under [Unreleased].
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.
Closes #2704.
The problem
Document.getPlainText(index, len)repeats the document's content whenlenislarger than the document:
A blank document repeats its trailing newline the same way.
Root cause
Line._getPlainText(lib/src/document/nodes/line.dart) wrapped its whole bodyin
while (len0 > 0). That body already traverses the entire reachable document:the inner
whilewalks the current line's leaves, and thenextLinerecursionwalks every following line. Once the document was shorter than
len, the outerloop ran again and re-processed the same nodes from the original
offset,padding the result by repeating the content. It is now a single pass.
Tests
Added a "getPlainText beyond document length" group to
test/document/document_test.dart, covering an oversizedlenand a blankdocument. Existing tests are unaffected: every current
getPlainTextassertionrequests
lenequal to the available content, so none hit the repeat branch.A note on how I verified
My machine is on Flutter 3.41 and this package's editor widgets need 3.44, so I
verified on the v11.5.0 tag, where
Line._getPlainTextis identical to master.There the repro fails before the fix and passes after it, and the document suite
is green (17 tests). The change itself is a single
whilebecomingif, so CIon 3.44 is the final gate.