Already clicked bug

Created on 4 October 2018, over 5 years ago
Updated 25 July 2023, 11 months ago

There is a major bug in code on defining if current user has already liked content or not.

Here is a code (LikeDislikeController, line 128):

$already_clicked = key_exists($user, array_keys((array) $users));

The problem is that '(array) $users' gives a hash like this: '['default' => 'default', 1 => 'like',]'.
Taking keys from it will give this list: ['default', 1] with keys 0 and 1.
The code 'key_exists($user, array_keys((array) $users));' checks if key with value equals to current user id is among keys of array $users.

There are 2 problems:

1. key_exists - is deprecated function.
2. instead of checking if user id is among keys of result of array_keys, it should check if user id is in array of array_keys: in_array($user, array_keys((array) $users));

🐛 Bug report
Status

Fixed

Version

2.2

Component

Code

Created by

🇫🇮Finland aleksi_anisimov Helsinki

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.

  • 🇮🇳India heykarthikwithu Bengaluru 🌍

    Thanks you all for working on this issue.

    Done some major fixes around like & dislikes within 2.2.0 release,
    Have a check if this issue still exist with 2.2.0 version?

    Please check for the module page for the features covered.

  • Assigned to sahil.goyal
  • Issue was unassigned.
  • Status changed to RTBC 11 months ago
  • 🇮🇳India sahil.goyal

    Hi @tatewaky, there is no need for patch, as described in #11 the issue has been observed and fixed with the version 2.2.0. As of PHP 7.4.0,
    The key_exists() function has been deprecated in favour or of using the array_key_exists() function for PHP 8 and instead to ensure backward compatibility.
    As in problem 2 described also addressed in version 2.2.0 as avoided the unnecessary overhead of using array_keys() just for checking existence with in_array.

    Hence, In updated version functionality works as expected and no issue has been observed.

  • Status changed to Fixed 11 months ago
  • 🇮🇳India heykarthikwithu Bengaluru 🌍

    Thank you all :)

    Note: Use the latest version of the module & Please check for the module page for the features covered.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024