Skip to content

Fix CRLF line ending handling in user section preservation #8

@tsavo-at-pieces

Description

@tsavo-at-pieces

Overview

File: lib/src/cli/utils/workflow_generator.dart line 145

The user section regex uses literal \n:

RegExp(r'# --- BEGIN USER: (\S+) ---\n(.*?)# --- END USER: \1 ---', dotAll: true)

If a CI file has CRLF line endings (e.g., edited on Windows, or checked out with core.autocrlf=true), the regex won't match \r\n. All user sections are silently discarded and overwritten with empty ones. This is a data-loss bug.

Similarly, the empty-section replacement on line 163 uses \n literally in the pattern string.

Reproduction

sed -i 's/$/\r/' .github/workflows/ci.yaml
dart run runtime_ci_tooling:manage_cicd update --workflows
# All user content vanishes

Fix

Normalize line endings at the top of _preserveUserSections:

existing = existing.replaceAll('\r\n', '\n');
rendered = rendered.replaceAll('\r\n', '\n');

Or use \r?\n in the regex.

Acceptance Criteria

  • User sections preserved regardless of line ending style
  • Test added with CRLF content
  • Warning logged if CRLF detected in input

Metadata

Metadata

Labels

P2-mediumMedium priorityarea/templateTemplate engine and skeleton filesbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions