Problem/Motivation

`PluginRevisionController::buildRevisionsNavigation()` accesses `$revision_ids[$i - 1]` on line 249 without checking that `$i > 0`. When `$i` stays at `0` (because the right revision ID is absent from the language-filtered revision list — a valid scenario for translatable nodes with `und`-language revisions), the access resolves to `$revision_ids[-1]`, which is undefined:

```
Warning: Undefined array key -1 in Drupal\diff\Controller\PluginRevisionController->buildRevisionsNavigation() (line 249 of modules/contrib/diff/src/Controller/PluginRevisionController.php).
```

The equivalent "previous change" block is correctly guarded by `if ($i !== 0)` on line 233; the "next change" block on line 249 is not.

Steps to reproduce

1. Have a translatable node with `und`-language revisions
2. Visit the split_fields diff page (e.g. `/en/node/{nid}/revisions/view/{left_vid}/{right_vid}/split_fields`)
3. Observe the PHP warning in the logs

Proposed resolution

Replace the access to `$revision_ids[$i - 1]` with a direct comparison against `$right_revision_id`, which is always available and semantically equivalent. When `$i > 0`, `$revision_ids[$i - 1]` equals `$right_revision_id` (the while loop guarantees this). When `$i === 0`, the original code crashes; the fix correctly uses the always-available variable.

CommentFileSizeAuthor
#2 diff-undefined-array-key-3630570-2.patch779 bytesadhariwal

Issue fork diff-3630570

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

adhariwal created an issue. See original summary.

adhariwal’s picture

StatusFileSize
new779 bytes
acbramley’s picture

Version: 2.1.1 » 2.x-dev
Status: Needs review » Needs work
Issue tags: -Needs review, -bug +Needs issue summary update

Can you please update the IS with the default template (it looks like markdown was used) and post the changes as an MR. Patches are not accepted.

acbramley’s picture

Issue summary: View changes

acbramley’s picture

Status: Needs work » Needs review

I couldn't reproduce this with language filtering but was able to derive a test with the query alter that hits the same warning. Are you able to provide steps to reproduce using different languages?