Repository navigation
Treat CRLF like LF in LicenseEntryWithLineBreaks - #189336
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies LicenseEntryWithLineBreaks to handle CRLF line endings by stripping trailing carriage returns (\r) and adds a unit test to verify this behavior. The review feedback recommends replacing the assert(lineStart < lineEnd) assertion with a safe conditional check to avoid potential debug-mode crashes on malformed license files, and expanding the test case to include a trailing carriage return to ensure robustness.
| assert(lineStart < lineEnd); | ||
| lines.add(text.substring(lineStart, lineEnd)); |
There was a problem hiding this comment.
Using assert(lineStart < lineEnd) can cause runtime crashes in debug mode if the license text contains a line consisting of only \r (for example, if the file ends with \n\r or just \r). Since assertions are evaluated in debug mode, a malformed license file in a package could crash the developer's application when the licenses page is opened.
Instead of asserting, we should safely guard the addition to lines by checking if lineStart < lineEnd.
if (lineStart < lineEnd) {
lines.add(text.substring(lineStart, lineEnd));
}There was a problem hiding this comment.
I don't think the suggested guard is correct for this state machine.
A standalone \r after \n, or an input containing only \r, is handled while the parser is in beforeParagraph, so it does not reach addLine(). For the EOF case this change is targeting, such as A\r, stripping the trailing CR still leaves lineStart < lineEnd.
Also, guarding only lines.add(...) would be incomplete because some callers expect addLine() to have produced a line before calling getParagraph().
| final List<LicenseParagraph> paragraphs = const LicenseEntryWithLineBreaks( | ||
| <String>[], | ||
| 'A\r\nB\r\nC\r\n\r\nD\r\nE', | ||
| ).paragraphs.toList(); |
There was a problem hiding this comment.
To ensure robustness against malformed inputs (such as files ending with a trailing \r or \n\r), we should include a trailing \r in the test case input. This will verify that the parser does not crash and correctly handles these edge cases.
| final List<LicenseParagraph> paragraphs = const LicenseEntryWithLineBreaks( | |
| <String>[], | |
| 'A\r\nB\r\nC\r\n\r\nD\r\nE', | |
| ).paragraphs.toList(); | |
| final List<LicenseParagraph> paragraphs = const LicenseEntryWithLineBreaks( | |
| <String>[], | |
| 'A\\r\\nB\\r\\nC\\r\\n\\r\\nD\\r\\nE\\r\\n\\r', | |
| ).paragraphs.toList(); |
There was a problem hiding this comment.
I'd prefer to keep this test focused on CRLF line endings inside normal hard-wrapped paragraphs and CRLF paragraph boundaries.
A trailing standalone \r after a line break is handled while the parser is in beforeParagraph, so it does not exercise the addLine() path fixed by this PR. A malformed EOF-only trailing \r case would be a separate robustness test, but I would rather not broaden this PR unless a maintainer asks for it.
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍 . I'm on board with your assessment of the Gemini review comments. I think I agree with you that we probably should have handled CRLF in addLine as well from the start. Thanks for fixing!
|
Thanks for the review! Google testing is failing with "Internal smoke tests failed. Please contact a Google developer to help investigate the failure." Could you help check whether this is related to this PR? |
|
Can you rebase to refresh CI here? We rolled out some updates to how tests run. |
a851784 to
86571d8
Compare
86571d8 to
a49c18e
Compare
|
@Piinks Rebased and pushed. GitHub checks have been refreshed. Thanks! |
|
The failure seemed to just be because the PR was out of date, so I've updated it. |
|
This PR was approved on July 14 and CI has been passing since the branch update on July 28. Is there anything else needed before adding the autosubmit label? |
|
I'd like to raise this as a process problem, not just ask for a merge. This PR was approved on 2026-07-14, 27 days ago. The diff has not changed since 07-22 ( The check history shows this was not simply a matter of waiting on CI. After the 07-28 branch update ( That window did not end by landing. It ended with another master merge ( To be clear, I am not criticizing the reviews — the reviews were prompt, and the branch updates were well intentioned. What I am raising is structural:
The net effect is that an approved, unmodified PR from an external contributor can be green for five days, go stale, and sit for a month, with no action available to the contributor to change that. Concretely: could someone retry the internal tests and apply |
|
Friendly ping @justinmc @Piinks @AbdeMohlbi — could someone please retry the internal |
|
Hey @motucraft I understand your frustration here. Reviews have been delayed lately as we have been overwhelmed with agent generated PRs. We enabled PR limits soon after Github introduced the feature last month to prevent this, and have been working to catch up. I appreciate your patience while we have been working through the review queue. A bit more context as well, when Google testing fails, that means internal tests are failing with this change. It requires we then investigate and often work with customers internally to find out what is failing and why. Sometimes it means we need to land changes to the internal code to unblock PRs. While it may seem like there is not a lot of activity on the PR, there could be a lot of work going on internally in order to unblock it. |
Just more context, this is common to update and re-run the internal tests under updated conditions. |
|
Here are our docs as well wrt code review expectations. :) https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#getting-a-code-review |
|
@Piinks The part I’m trying to call out is that external contributors have no visibility into that state. From my side, I can only see an internal |
|
I am rebasing to update the base commit. I needs to be within 7 days in order to be mergable. |
LicenseEntryWithLineBreaks recognized CRLF at paragraph boundaries, but addLine() did not strip the trailing carriage return when collecting hard-wrapped lines within a paragraph. As a result, CRLF-terminated license text kept \r characters in LicenseParagraph.text and rendered differently from the equivalent LF text. Drop a trailing \r in addLine() so a CRLF line ending is treated the same as an LF line ending. Add a test covering reflow and paragraph splitting with CRLF input. Fixes flutter#189313
b07514e to
1777461
Compare
|
autosubmit label was removed for flutter/flutter/189336, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
LicenseEntryWithLineBreaks recognized CRLF at paragraph boundaries, but addLine() did not strip the trailing carriage return when collecting hard-wrapped lines within a paragraph. As a result, CRLF-terminated license text kept
\rcharacters in LicenseParagraph.text and rendered differently from the equivalent LF text.Drop a trailing
\rin addLine() so a CRLF line ending is treated the same as an LF line ending. Add a test covering reflow and paragraph splitting with CRLF input.Fixes #189313
Local validation
flutter test test/foundation/licenses_test.dartpassed.flutter analyze --flutter-repo lib/src/foundation/licenses.dart test/foundation/licenses_test.dartpassed.git diff --checkpassed.I also ran the full
flutter testlocally. It failed due to unrelated golden pixel diffs outside this change; the newlicenses_test.dartcase passed during that run.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.