Skip to content

Fix duplicate key collisions for form/field keys over 60 characters - #3622

Open
vivi-the-going-merry[bot] wants to merge 4 commits into
masterfrom
fix/issue-6902-long-key-duplicate
Open

vivi-the-going-merry[bot] wants to merge 4 commits into
masterfrom
fix/issue-6902-long-key-duplicate

Conversation

@vivi-the-going-merry

Copy link
Copy Markdown
Contributor

Fixes Strategy11/formidable-pro#6902

Broken: a form or field key longer than 60 characters is cut to 60 before the numeric suffix is appended, but the list of existing similar keys was loaded for the full key. Copies already made from the truncated key (…2, …3) weren't in that list, so the second duplicate got …2 again and failed on the unique index (form), or the field was silently dropped (61–69 character field keys).

Changed: FrmAppHelper::get_unique_key() reloads the similar keys after truncating. The query is extracted into a private get_similar_keys() so it isn't written twice.

Verified:

  • New test_get_unique_key_increments_for_truncated_long_key failed before the fix (…2 returned where …3 expected) and passes after.
  • tests/phpunit/misc/test_FrmAppHelper.php: 51/51 green locally. Full Lite suite: 950 tests, 6 failures, all from view-transitions.min.css / wp-commands stylesheet files missing from the local WordPress checkout — unrelated to this change.
  • CI: see checks below.

🤖 Generated with Claude Code

vivi-the-going-merry Bot and others added 3 commits October 26, 2026 10:41
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in a0b9742...c4bf9c9 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Oct 26, 2026 4:44p.m. Review ↗
JavaScript Oct 26, 2026 4:44p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

$this->factory->form->create( array( 'form_key' => $long_key ) );

$first = FrmAppHelper::get_unique_key( $long_key, $table_name, $column );
$this->assertSame( $truncated . '2', $first );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAppHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->factory->form->create( array( 'form_key' => $first ) );

$second = FrmAppHelper::get_unique_key( $long_key, $table_name, $column );
$this->assertSame( $truncated . '3', $second, 'The suffix should skip keys already created from the truncated key.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAppHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Oct 26, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 125f459. Non-blocking, nothing to fix.

Before/after run (PHPUnit, wp-env tests container, Lite master a0b9742 as base):

  • Base code + this PR's new test_get_unique_key_increments_for_truncated_long_key: fails. It returns …aaaa2 where …aaaa3 is expected, which is the duplicate-suffix collision from the bug report.
  • PR code, same test: passes. The full test_FrmAppHelper.php file is 51 tests, 2 failures (test_site_url, test_get_server_value). Both compare against example.org and get localhost:4013 from the harness host. They fail identically on base, so they are environment noise and unrelated to this change.

Code read:

  • get_unique_key() only reloads the similar-keys list when maybe_truncate_key_before_appending() actually changed the key, so keys of 60 characters or fewer take the same path and do the same single query as before.
  • The reload uses the truncated key, so …2, …3 copies are now in the list and the suffix loop skips them. The is_numeric → a branch is handled because the reload runs on the already-adjusted key.
  • get_similar_keys() is a straight extraction of the old query, no behavior change.

CI: Psalm is red, but every error I opened is MissingPureAnnotation on lines this PR doesn't touch, and master's own Psalm run is red too. Most other jobs were skipping at this head (no run tests/run analysis label), so PHPUnit was only run by me, above.

Not run: field-key (61–69 character) path live in the builder (same function, source-read only), code-review/security-review/simplify skills (46-line diff read in full instead), PHPStan/PHPCS.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Oct 26, 2026
@Crabcyborg Crabcyborg added this to the 7.1 milestone Oct 26, 2026

@garretlaxton garretlaxton left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants