Skip to content

fix(android,flutter): Preserve CRLF line endings when present#1253

Merged
andreiborza merged 4 commits intomasterfrom
ab/flutter-lf-crfl
Apr 7, 2026
Merged

fix(android,flutter): Preserve CRLF line endings when present#1253
andreiborza merged 4 commits intomasterfrom
ab/flutter-lf-crfl

Conversation

@andreiborza
Copy link
Copy Markdown
Member

This PR fixes mixed line endinges when the wizard modifies files that have CRLF (\r\n) line endings. Previously we would always append LF (\n), thus mixing line endings, causing issues on platforms that use CRLF.

It adds a fixLineEndings() post-processing step for Android and Flutter wizards that detects modified files with CRLF and normalizes any LF to CRLF.

Other wizards use proper formatters or don't suffer from this issue.

Closes: #1249

@andreiborza andreiborza requested review from JPeer264 and denrase April 7, 2026 07:09
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes

  • (android,flutter) Preserve CRLF line endings when present by andreiborza in #1253

Internal Changes

  • (agents) Convert commands to dotagents skills by chargome in #1236
  • Pin GitHub Actions to full-length commit SHAs by joshuarli in #1244

🤖 This preview updates automatically when you update the PR.

@andreiborza andreiborza requested a review from Lms24 April 7, 2026 07:09
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Flutter wizard fixes line endings before MCP writes files
    • Moved fixLineEndings() call to after offerProjectScopedMcpConfig() to match the Android wizard pattern and ensure all modified files are processed.

Create PR

Or push these changes by commenting:

@cursor push 29226be55e
Preview (29226be55e)
diff --git a/src/flutter/flutter-wizard.ts b/src/flutter/flutter-wizard.ts
--- a/src/flutter/flutter-wizard.ts
+++ b/src/flutter/flutter-wizard.ts
@@ -161,9 +161,6 @@
   }
   Sentry.setTag('main-patched', mainPatched);
 
-  // Fix mixed line endings caused by inserting LF content into CRLF files (Windows)
-  fixLineEndings();
-
   // ======== OUTRO ========
 
   // Offer optional project-scoped MCP config for Sentry with org and project scope
@@ -172,6 +169,9 @@
     selectedProject.slug,
   );
 
+  // Fix mixed line endings caused by inserting LF content into CRLF files (Windows)
+  fixLineEndings();
+
   const issuesPageLink = selfHosted
     ? `${sentryUrl}organizations/${selectedProject.organization.slug}/issues/?project=${selectedProject.id}`
     : `https://${selectedProject.organization.slug}.sentry.io/issues/?project=${selectedProject.id}`;

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4423739. Configure here.

This PR fixes mixed line endinges when the wizard modifies files that have CRLF
(\r\n) line endings. Previously we would always append LF (\n), thus mixing line
endings, causing issues on platforms that use CRLF.

                                                                                       It adds a `fixLineEndings()` post-processing step for Android and Flutter
wizards that detects modified files with CRLF and normalizes any LF to CRLF.

Other wizards use proper formatters or don't suffer from this issue.

Closes: #1249
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

LGTM

Tests are failing though

Copy link
Copy Markdown
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

naive question: If the LF endings only come from the files our wizard touches, could we use os.EOL to use the correct line breaks in the code modifications directly? Wondering if this isn't better than the post processing step but if there's a good reason for it, then no objections :)

@andreiborza
Copy link
Copy Markdown
Member Author

andreiborza commented Apr 7, 2026

@Lms24 I was initially thinking of going that route but it seemed less safe to me, what if the environment that runs the wizard is not the same as the environment that runs the app?

A post-processing step seemed more in line with what we do with the js wizards with prettier.

]);

export function fixLineEndings(): void {
const files = getUncommittedOrUntrackedFiles()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The new fixLineEndings function relies on a utility that incorrectly parses file paths with spaces, causing those files to be silently skipped during line ending normalization.
Severity: MEDIUM

Suggested Fix

Modify getUncommittedOrUntrackedFiles to correctly parse filenames with spaces. The recommended approach is to use git status --porcelain -z, which provides NUL-terminated output, making parsing unambiguous and robust.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/utils/line-endings.ts#L29

Potential issue: The `getUncommittedOrUntrackedFiles` function parses `git status`
output by splitting on whitespace. This causes it to incorrectly handle filenames that
contain spaces, truncating the path. The new `fixLineEndings` function calls this
pre-existing utility. As a result, any uncommitted files with spaces in their names will
be silently skipped during the line-ending normalization process, leading to an
incomplete fix for users on Windows environments where this is common.

Copy link
Copy Markdown
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Good point, thanks for explaining!

@andreiborza andreiborza merged commit 3e54be3 into master Apr 7, 2026
57 checks passed
@andreiborza andreiborza deleted the ab/flutter-lf-crfl branch April 7, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sentry-wizard.exe corrupts source files by putting LF line endings in CRLF files

3 participants