honeypot_get_protected_forms() doesn't always return an array

Created on 16 February 2022, over 2 years ago
Updated 22 June 2023, about 1 year ago

I encountered this when working on #2949447: Expose honeypot protection via service β†’ - I added a simple test case to test that calling honeypot_get_protected_forms(), which is deprecated by the patch in that issue, properly returned an array and triggered the deprecation message.

What I found out is that honeypot_get_protected_forms() doesn't always return an array! Sometimes it returns NULL. The problem is subtle, since it almost always works, and only fails when no forms are checked as 'protected'. However, because this is the default configuration, the problem is always seen in the tests. It doesn't cause an error in the honeypot.module code only because the code performs an excess check to see if honeypot_get_protected_forms() is TRUE before using the output. An array is "TRUE" in PHP. NULL is not. This check should not be needed.

With honeypot_get_protected_forms() fixed to always return an array, the code in honeypot_form_alter() can then be simplified to remove the excess check mentioned above and to remove an excess loop. This makes the code, which runs on every form, quicker and easier to read/understand.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States TR Cascadia

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    Not currently mergeable.
  • @michellesfrazer opened merge request.
Production build 0.69.0 2024