Skip to content

Code fixer corrupts file by appending trailing characters to comment lines #4492

@thomhurst

Description

@thomhurst

Description

The NUnit migration code fixer (TUNU0001) occasionally corrupts source files by appending trailing characters to lines, particularly comment lines. This appears to be a text manipulation bug where characters from elsewhere in the file get appended to unrelated lines.

Reproduction Steps

This issue was discovered during a large-scale migration. After running:

dotnet format analyzers --severity info --diagnostics TUNU0001

A license header comment was corrupted:

Before:

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and

After:

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.f
// See the License for the specific language governing permissions and

Note the trailing f character that was appended to line 12.

Expected Behavior

The code fixer should only modify code related to NUnit-to-TUnit migration. Comment lines and unrelated code should remain unchanged.

Environment

  • TUnit Version: 1.11.64
  • .NET SDK: 10.0.100-preview.1.25103.12
  • OS: Windows 11

Additional Context

This appears to be related to other text manipulation bugs reported:

These issues suggest the code fixer's text manipulation logic has edge cases that cause character displacement or corruption when processing complex files.

The corruption is subtle and easy to miss during code review, potentially causing issues later.


Note: Please add tests when fixing this issue to prevent regression. Consider adding tests that verify the fixer doesn't modify lines it shouldn't touch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions