Php-cs-fixer: binary_operator_spaces breaks array keys containing UTF8 characters

Created on 3 Nov 2017  路  3Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using:

7.1.8

PHP CS Fixer version you are using:

2.7.1

The command you use to run the fixer (and the configuration file you are using if any).

vendor/bin/php-cs-fixer fix xxxx.php

// .php_cs

return PhpCsFixer\Config::create()
    ->setFinder($finder)
    ->setRules([
        'binary_operator_spaces' => [
            'operators' => [
                '=>'  => 'align_single_space_minimal',
            ],
        ],
    ]);

A minimal sample of valid PHP code that is not fixed correctly (if applicable).

before.php.txt

The fixed version of that code after you run the fixer and the version you expected.

after.php.txt

The fixer is incorrectly adding a space inside the third array key.

$ diff before.php after.php
4,7c4,7
<       'ait臈\b' => 'as',
<       'yt臈\b'  => 'is',
<       'i奴t臈\b' => 'ius',
<       'ut臈\b'  => 'us',
---
>       'ait臈\b'  => 'as',
>       'yt臈\b'   => 'is',
>       'i奴t臈\b ' => 'ius',
>       'ut臈\b'   => 'us',

Most helpful comment

I can confirm that 2.8.0 fixes the problem.

I hadn't seen this release - until a few hours ago, composer update was only giving me 2.7.1

All 3 comments

A similar bug was fixed in #3117 which is part of recent 2.7.2 release. Could you try this version to see if it fixes the problem?

I can confirm that 2.8.0 fixes the problem.

I hadn't seen this release - until a few hours ago, composer update was only giving me 2.7.1

was fixed in 2.7.2 actually

Was this page helpful?
0 / 5 - 0 ratings