DiffOpOutputBuilder does not correctly match the 10.0.x implementation and produces unexpected output

Created on 11 September 2023, over 1 year ago

Problem/Motivation

The \Drupal\Component\Diff\DiffOpOutputBuilder implementation added in 📌 Deprecate DiffEngine and replace with sebastian/diff Fixed doesn't match the ouput of 10.0.x diffing. This results in test failures for the update_helper module on 10.1.x.

Steps to reproduce

$a = <<<EOF
settings
settings::max_length : i:123;
status : b:0;
translatable : b:1;
EOF;

$b = <<<EOF
settings : a:0:{}
status : b:1;
translatable : b:1;
EOF;

$a = explode("\n", $a);
$b = explode("\n", $b);

$diff = new \Drupal\Component\Diff\Diff($a, $b);

dump($diff->getEdits());

On 10.0.x this produces:

^ array:2 [
  0 => Drupal\Component\Diff\Engine\DiffOpChange^ {#2855
    +type: "change"
    +orig: array:3 [
      0 => "settings"
      1 => "settings::max_length : i:123;"
      2 => "status : b:0;"
    ]
    +closing: array:2 [
      0 => "settings : a:0:{}"
      1 => "status : b:1;"
    ]
  }
  1 => Drupal\Component\Diff\Engine\DiffOpCopy^ {#2915
    +type: "copy"
    +orig: array:1 [
      0 => "translatable : b:1;"
    ]
    +closing: array:1 [
      0 => "translatable : b:1;"
    ]
  }
]

On 10.1.x this produces:

^ array:3 [
  0 => Drupal\Component\Diff\Engine\DiffOpChange^ {#1898
    +type: "change"
    +orig: array:2 [
      0 => "settings"
      1 => "settings::max_length : i:123;"
    ]
    +closing: array:2 [
      0 => "settings : a:0:{}"
      1 => "status : b:1;"
    ]
  }
  1 => Drupal\Component\Diff\Engine\DiffOpDelete^ {#1930
    +type: "delete"
    +orig: array:1 [
      0 => "status : b:0;"
    ]
    +closing: false
  }
  2 => Drupal\Component\Diff\Engine\DiffOpCopy^ {#1727
    +type: "copy"
    +orig: array:1 [
      0 => "translatable : b:1;"
    ]
    +closing: array:1 [
      0 => "translatable : b:1;"
    ]
  }
]

Proposed resolution

This is due to how DiffOpOutputBuilder changes a series of deletions and additions into a change.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.1

Component
Base 

Last updated about 2 hours ago

Created by

🇬🇧United Kingdom alexpott 🇪🇺🌍

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

Comments & Activities

Production build 0.71.5 2024