phpcbf produces incorrect results in some cases with CRLF line endings

Created on 12 June 2025, about 1 month ago

Problem/Motivation

Under some circumstances, phpcbf produces some incorrect results when using CRLF line endings with the current (and also some older) version(s) of Coder when running phpcbf on a file.

Steps to reproduce

- Create a file with the following content (with CRLF line breaks):

<?php

/**
 * Implements hook_theme().
 */
function example_theme($existing, $type, $theme, $path): array {
  return [];
}

- Run phpcbf on the file (with "Drupal" coding standard).
- phpcbf produces the following result:

<?php

/**
 * @file
 * @file
 * @file
 * .*/

/**
 * Implements hook_theme(). *
 */ example_theme($existing, $type, $theme, $path): array {
return [];
}

- With LF line endings, the result is produced as expected.

I have also attached a (minimal) setup (including config) that causes the issue for me:
- Unzip the directory
- Run "composer install" in the directory
- Run "./vendor/bin/phpcbf .\example_broken.php" → This produces the incorrect result.
- Run "./vendor/bin/phpcbf .\example_works.php" → This produces the expected result.

The only diff between the two files should be the line endings.

At some point while testing, I also had a version with CRLF endings where phpcbf ran into some infinite loop and then aborted because of this (while it again worked fine with LF endings). I was not able to reproduce this anymore though, so I am not sure under which exact conditions this happens.

There was also a similar issue with line endings in the past, I don't know if they may be related: https://www.drupal.org/project/coder/issues/3307937 🐛 phpcbf fails with "Uninitialized string offset" on CRLF line endings Fixed

Proposed resolution

tbd

Remaining tasks

- Fix

🐛 Bug report
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024