8

I have an update server for my extensions, which targets Joomla 3.8 and 3.9

<targetplatform name="joomla" version="3.[89]"/>

With the release of Joomla 3.10 and 4.0 coming soon, how would I add support for both of these?

I know I can add two separate <update> blocks for 3.x and 4.x, but I'd rather use a regex to support both in a single block.

Would something like this work?

<targetplatform name="joomla" version="(3.[89]|10)|4.*"/>
2
  • Sorry re-read your question more thoroughly and realised you already knew my suggestion. Cheers. Commented Aug 17, 2021 at 9:57
  • @Lodder for comparison against my answer see this demonstration of your attempted pattern: regex101.com/r/nvWYsG/1 Commented Aug 18, 2021 at 23:20

1 Answer 1

6

Based on this link that Roland Dalmulder sent me to:

https://github.com/joomla/joomla-cms/blob/5fdba4e5ee022517a05ae893d8f7077eaf864bf7/libraries/src/Updater/Adapter/ExtensionAdapter.php#L113

preg_match('/^' . $this->currentUpdate->targetplatform['VERSION'] . '/', JVERSION)

There is no implementation of preg_quote(), so the dots (any character / wildcard) will need escaping.

I recommend:

<targetplatform name="joomla" version="(4|3\.([89]|10))\b"/>
// same but slightly less efficient:   ((3\.([89]|10))|4)\b 

I have removed the trailing .* because that matching will do nothing to improve the validation.

Breakdown: (Regex101 Demo with battery of test cases)

/         # opening pattern delimiter
^         # match start of the string (zero-width match)
(         # begin capture group 1
  4       # match a 4
  |       # or
  3\.     # match a 3, then a dot
  (       # begin capture group 2
    [89]  # match an 8 or a 9
    |     # or
    10    # match a 1 then a 0 (which obviously forms 10)
  )       # end capture group 2
)         # end capture group 1 
\b        # a word boundary metacharacter to prevent longer integer values (zero-width match)
/         # closing pattern delimiter
1
  • 1
    Ah, hadn't thought of 3|4 and using a word boundary. Thanks.
    – Lodder
    Commented Aug 19, 2021 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.