Skip to content

Treat CRLF like LF in LicenseEntryWithLineBreaks - #189336

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
motucraft:fix/license-crlf-line-endings
Aug 15, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
motucraft:fix/license-crlf-line-endings

Conversation

@motucraft

@motucraft motucraft commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

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 #189313

Local validation

  • flutter test test/foundation/licenses_test.dart passed.
  • flutter analyze --flutter-repo lib/src/foundation/licenses.dart test/foundation/licenses_test.dart passed.
  • git diff --check passed.

I also ran the full flutter test locally. It failed due to unrelated golden pixel diffs outside this change; the new licenses_test.dart case 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-assist bot 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.

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 12, 2026
@motucraft
motucraft marked this pull request as ready for review July 12, 2026 05:12

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +170 to +171
assert(lineStart < lineEnd);
lines.add(text.substring(lineStart, lineEnd));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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));
      }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Comment on lines +183 to +186
final List<LicenseParagraph> paragraphs = const LicenseEntryWithLineBreaks(
<String>[],
'A\r\nB\r\nC\r\n\r\nD\r\nE',
).paragraphs.toList();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@motucraft

Copy link
Copy Markdown
Contributor Author

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?

@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label Jul 15, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 15, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label Jul 15, 2026
@Piinks

Piinks commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Can you rebase to refresh CI here? We rolled out some updates to how tests run.

@motucraft
motucraft force-pushed the fix/license-crlf-line-endings branch from a851784 to 86571d8 Compare July 22, 2026 00:50
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 22, 2026
@motucraft
motucraft force-pushed the fix/license-crlf-line-endings branch from 86571d8 to a49c18e Compare July 22, 2026 02:50
@motucraft

motucraft commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@Piinks Rebased and pushed. GitHub checks have been refreshed. Thanks!

@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label Jul 22, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 28, 2026
@justinmc

Copy link
Copy Markdown
Contributor

The failure seemed to just be because the PR was out of date, so I've updated it.

@justinmc justinmc added the CICD Run CI/CD label Jul 28, 2026
@motucraft

Copy link
Copy Markdown
Contributor Author

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?

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 3, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label Aug 3, 2026
@motucraft

Copy link
Copy Markdown
Contributor Author

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 (a49c18e), and no code changes have been requested since approval. It is now a month old and still has not landed.

The check history shows this was not simply a matter of waiting on CI. After the 07-28 branch update (c35c122, pushed by a maintainer, not by me), this PR was approved, carried the CICD label, and had every check green — the last one, Tree_analyze, completed at 07-29 05:46. It stayed in that state until 08-03 15:11, about 5 days and 9 hours.

That window did not end by landing. It ended with another master merge (b07514e, also pushed by a maintainer), and the Google testing failure that now blocks this PR first appeared on that merge, at 08-03 17:06. It has sat untriaged for a week. So the check that is red today is a consequence of that update, not the reason the PR failed to land during the 5 days it was green.

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:

  • Google testing took 1h54m, 2h50m and 7h46m across the three runs on this PR, and it is invalidated by every branch update. In practice, that makes it easy for the valid green window to expire before the required member-only action happens.
  • flutter-dashboard[bot] strips CICD on every branch update, and an external contributor cannot re-add it. It was re-added by hand four times here. I cannot make CI progress without a member doing that each time.
  • go/frob_pr/189336 is Google-internal. I cannot view, debug, or retry the one check that is blocking my own PR.
  • Approval and responsibility for landing are separate, and nothing assigns the latter. I asked on 08-03 what was needed, and no one has replied in the week since.

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 autosubmit if they come back green? And if there is a documented path for contributors in this situation, I would like to know it, because I was not able to find one.

@motucraft

Copy link
Copy Markdown
Contributor Author

Friendly ping @justinmc @Piinks @AbdeMohlbi — could someone please retry the internal Google testing, and apply autosubmit if it comes back green?

@Piinks

Piinks commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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.

@Piinks

Piinks commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

It ended with another master merge (b07514e, also pushed by a maintainer)

Just more context, this is common to update and re-run the internal tests under updated conditions.

@Piinks

Piinks commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

@motucraft

Copy link
Copy Markdown
Contributor Author

@Piinks
Thanks for the context. I understand that internal failures may require internal investigation, and that work may be happening outside the PR.

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 Google testing failure that I cannot inspect or retry, and no indication of whether it is being investigated, waiting for an owner, or blocked on something else.

@Piinks

Piinks commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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
@Piinks
Piinks force-pushed the fix/license-crlf-line-endings branch from b07514e to 1777461 Compare August 14, 2026 17:32
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 14, 2026
@Piinks Piinks added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Aug 14, 2026
@auto-submit

auto-submit Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 14, 2026
@AbdeMohlbi AbdeMohlbi added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 15, 2026
Merged via the queue into flutter:master with commit d26b43a Aug 15, 2026
35 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2026
@motucraft
motucraft deleted the fix/license-crlf-line-endings branch August 25, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LicenseEntryWithLineBreaks leaves carriage returns in paragraphs with CRLF line endings

4 participants