PR-5.4-dev Pending

User tests: Successful: Unsuccessful:

avatar beni71
beni71
7 Dec 2025

Pull Request for Issue #41183 .

Summary of Changes

The banners module supports using banners by tag search or keywords. When the banners model is building the query for it, there is a reg-expression to search for words. This regex seems not be compatible with MySql version 8.0.4 and newer.

The SQL query, which is created, is something like: Where metakey regexp('[[:<:]]Mo[[:>:]]')
"Mo" is the keyword to search for.

Executing it on MySql 8.0.4 or any newer version, it throws the error "Illegal argument to a regular expression.".
I think the correct reg-expression must be: Where metakey regexp('\\bMo\\b')

In the MySql manual https://dev.mysql.com/doc/refman/8.0/en/regexp.html there is the explanation about the switch from the Henry Spencer's implementation to the ICU compatible implementation:

MySQL implements regular expression support using International Components for Unicode (ICU), which provides full Unicode support and is multibyte safe. (Prior to MySQL 8.0.4, MySQL used Henry Spencer's implementation of regular expressions, which operates in byte-wise fashion and is not multibyte safe.

Further information in the web can for example be found here:
https://bugs.mysql.com/bug.php?id=106504
https://stackoverflow.com/questions/59998409/error-code-3685-illegal-argument-to-a-regular-expression

System information:
Joomla: The site which had/has those issues had version 5 and is in the meantime migrated to 6 (where the errors still appear).
DB type: mysql
DB version: 8.0.42
PHP-Version: 8.4.7

Background information:
I use a custom component which calls in a view $this->getDocument()->setMetaData('keywords', $currentKeywords);
With this approach, the banners module gets those keywords in its BannersHelper method getBanners() line 45 with:
$keywords = explode(',', $app->getDocument()->getMetaData('keywords'));

With this Pull Request the reg-expression will be surrounded with a db type and version check, which makes sure the correct expression is used for both versions.

In the same part of the banners model there is

  • another fix for a null ref deprecation warning from PHP 8:

    Deprecated
    : str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in
    [root]\components\com_banners\src\Model\BannersModel.php on line 219

  • a fix for a PHP 8 warning:

    Warning
    : foreach() argument must be of type array|object, false given in
    [root]\components\com_banners\src\Model\BannersModel.php on line 275

Testing Instructions

Honestly, I don't know how I can provide the keywords with the Joomla standard components. So the easiest way to reproduce is:

  1. Activate maximum error reporting in the system configuration.
  2. In the banners component configuration, make sure in Tab "Client" the "Keyword Prefix" is empty.
  3. Create banner 1
    Under Tab Publishing, set a keyword into "Keywords": Mo
    set "Use Own Prefix" to Yes
    set "Keyword Prefix" to: Mo
  4. Create banner 2, with the same settings as mentioned for banner 1.
  5. Create banner 3, with the same settings as mentioned for banner 1, but set "Keywords": Di
  6. Create a site module banners
    Set a client
    Set a category.
    Set "Select by Keyword" to Yes.
  7. Now edit the module_banners in BannersHelper method getBanners() line 45, and replace
    $keywords = explode(',', $app->getDocument()->getMetaData('keywords'));
    with
    $keywords = ['Mo'];
  8. Clear cache.
  9. Open that menu item from the site and check the output.

Actual result BEFORE applying this Pull Request

  • No banners are visualized. The getItems method has catched the error "Illegal argument to a regular expression." but returned no banner data.
  • The PHP 8 deprecation warning "...Passing null to parameter #2 ($needle) of type string is deprecated..." is displayed.
  • The PHP 8 warning "...foreach() argument must be of type array|object, false given..." is displayed.

Expected result AFTER applying this Pull Request

  • Banner 1 and Banner 2 are visualized. (banners having "Keywords": Mo)
  • None of the two PHP 8 warnings are displayed.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar beni71 beni71 - open - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Dec 2025
Category Front End com_banners
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
Labels Added: PR-5.4-dev
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar brianteeman
brianteeman - comment - 7 Dec 2025

Related issue #41183 ?

avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 7 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 7 Dec 2025
avatar beni71 beni71 - change - 8 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 8 Dec 2025
avatar beni71
beni71 - comment - 8 Dec 2025

Good point, I didn't saw it. Yes, indeed, the word boundary part is the same. Although the related issue 41183 mentioned MariaDb as well and there is a discussion about a more generic/clean implementation. It seems that my PR is more like a quick fix.

@richard67 Since you were involved in the discussion of issue 41183, what do you think: Is my quick fix acceptable? I don't believe I'm capable of implementing the clean approach of extending the database providers.

avatar beni71 beni71 - change - 8 Dec 2025
The description was changed
avatar beni71 beni71 - edited - 8 Dec 2025
avatar richard67 richard67 - change - 8 Dec 2025
Title
Fix MySql 8 error "Illegal argument to a regular expression." in banners model
[5.4] Fix MySql 8 error "Illegal argument to a regular expression." in banners model
avatar richard67 richard67 - edited - 8 Dec 2025
avatar richard67
richard67 - comment - 8 Dec 2025

@richard67 Since you were involved in the discussion of issue 41183, what do you think: Is my quick fix acceptable? I don't believe I'm capable of implementing the clean approach of extending the database providers.

@beni71 If you accept my code change suggestions (can be done with buttons on GitHub), the PR is ok and can be changed from draft to ready for review.

avatar beni71
beni71 - comment - 8 Dec 2025

I have now a general question:
It seems that this PR is based on an old way to pass keywords to the banners module, throught the document, which was removed from the Joomla components with #25258. Joomla components no longer support it. Does it mean that it is deprecated anyway? If so, I will close the PR.

avatar richard67
richard67 - comment - 8 Dec 2025

To be honest: I have no idea if it is deprecated. Let's see if other comments come it.

The reason why I haven't made a PR yet for fixing the issue was because I was not able to find out how and when keywords were used in the banner module.

avatar richard67
richard67 - comment - 8 Dec 2025

As far as I know keywords of articles are used for the related articles module.

avatar beni71
beni71 - comment - 8 Dec 2025

Thanks, I will give it a try.

avatar richard67 richard67 - change - 8 Dec 2025
The description was changed
avatar richard67 richard67 - edited - 8 Dec 2025
avatar exlemor
exlemor - comment - 8 Dec 2025

@beni71 - first off, thank you for your contribution, unfortunately, I am not getting exactly what you are intending:
(just a small, perhaps obvious instruction update , you need to set a position for the module ;))

I set mine to Below_Top (and then Main_Bottom to see if that would change things... only difference is that with Main_Bottom I saw the Chrome with the title: Site Module Banner which isn't present in Below_top).

BEFORE CONDITION, I only match 2 out of 4 of your conditions,

  1. I get "No banners are visualized." - I do NOT have the error message: The getItems method has catched the error "Illegal argument to a regular expression." but returned

  2. The PHP 8 deprecation warning "...Passing null to parameter #2 ($needle) of type string is deprecated..." is displayed.

I get:

Deprecated
: str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in
/home/lights/public_html/_j540/components/com_banners/src/Model/BannersModel.php
on line
219

which seems to be a match!

  1. The PHP 8 warning "...foreach() argument must be of type array|object, false given..." is NOT displayed.

AFTER CONDITION: no more error message BUT no banner displayed. NO errors in Console in either case ;)

Hope that helps you!

Add a Comment

Login with GitHub to post a comment