- Posts: 94
- Thank you received: 13
Kunena 7.1.1 & Kunena 6.4.17 – Security Updates Released
The Kunena team has announce the arrival of Kunena 7.1.1 [K 7.1.1] in stable which is now available for download as a native Joomla extension for J! 5.4.x/6.0.x./6.1.x./6.2.x This version addresses most of the issues that were discovered in K 6.2 / K 6.3 / K 6.4 / K7.0 and issues discovered during the last development stages of K 7.1
Just a reminder: K6.4.17 receives only securities fixes until end of 2026, so it's advised for users to upgrade to K7.1.
Question Possible Bug in BBCodeLexer::guessTextLength() causes mod_kunenalatest issue
3 days 16 hours ago #235686
by guidocx84
Possible Bug in BBCodeLexer::guessTextLength() causes mod_kunenalatest issue was created by guidocx84
Hello, I've used the AI to solve this issue on my environment, so please analyse and confirm the solution if you want.I think I probably found a bug in Kunena's
that causes the message length limit in Kunena Latest (mod_kunenalatest) to be ignored under certain circumstances.After investigating the issue, I was able to reproduce it consistently and identify a possible fix.Environment
and the reply text makes the preview work correctly. Removing all BBCode and keeping the text as plain text also makes the limit work correctly.This allowed me to isolate the issue to the way the lexer estimates text length when processing certain combinations of BBCode and line breaks.Root causeThe problem appears to be in:
More specifically, in the
method.The current code contains a Kunena-specific modification intended to avoid a deprecated warning in PHP 8.5:
However,
iterates over
using its local
variable and does not call
.As a result,
is not updated during this method and remains empty.Consequently, the
condition is always false, the
is never executed, and the lexer state is not correctly updated. This causes
to underestimate the actual text length.In turn, NBBC may decide that the output is short enough and disable the configured output limit.Proposed fixI replaced the conditional block with the following code:
The important difference is that the
is always executed. When
is empty,
is set to
, avoiding the call to
with an empty string while preserving the original state-machine logic.ResultI tested this change in a separate test environment using the exact message that originally triggered the issue.After applying the modification:
Code:
BBCodeLexer.php
- Joomla: 5.4.11
- Kunena: 7.1.1
- Kunena Latest module: 6.2.2
- PHP: 8.3
- Maximum messages: 3
- Subject length: 50
- Tooltip message length: 150
- Message length limit: 150
- Configure the Kunena Latest module with a message length limit of 150 characters.
- Create a forum post containing nested BBCode quotes followed by a reply, with a line break between the closing nested quote tag and the reply text.
Code:
[quote="user1"]
[quote="user2"]This is the quoted text.[/quote]
This is the reply text, followed by enough content to exceed 150 characters...
[/quote]
Additional text...
- Check the message preview generated by the Kunena Latest module.
Code:
[/quote]
Code:
libraries/kunena/External/Nbbc/src/BBCodeLexer.php
Code:
guessTextLength()
Code:
if (!empty(substr($this->text, 0, 1))) {
switch (ord(substr($this->text, 0, 1))) {
// ...
}
}
Code:
guessTextLength()
Code:
$this->input
Code:
$text
Code:
nextToken()
Code:
$this->text
Code:
if
Code:
switch
Code:
guessTextLength()
Code:
else {
// Hack by Kunena : to remove the deprecated message with Php 8.5
$firstChar = ($this->text !== '') ? ord(substr($this->text, 0, 1)) : 0;
switch ($firstChar) {
case 10:
case 13:
$state = self::BBCODE_LEXSTATE_TEXT;
$length++;
break;
default:
$state = self::BBCODE_LEXSTATE_TEXT;
$length += strlen($text);
break;
case 40:
case 60:
case 91:
case 123:
$state = self::BBCODE_LEXSTATE_TEXT;
break;
}
// End Hack by Kunena
}
Code:
switch
Code:
$this->text
Code:
$firstChar
Code:
0
Code:
ord()
- The message preview is correctly truncated to 150 characters.
- The issue is no longer reproducible with nested quotes and line breaks.
- Plain-text messages continue to work as expected.
Please Log in or Create an account to join the conversation.
Less
More
- Posts: 1098
- Thank you received: 200
3 days 5 hours ago #235687
by Pinkeltje
Replied by Pinkeltje on topic Possible Bug in BBCodeLexer::guessTextLength() causes mod_kunenalatest issue
Thanks for the report. The nested quote example isn't really related: stripBBCode() removes quotes with a non-greedy regex before NBBC runs, so what's left there is under 150 chars (the stray [/quote] is a leftover of that regex).
But the guessTextLength() issue is real. Since the PHP 8.5 workaround, the state never goes back to TEXT after the first tag, so only the text before the first tag is counted. Easy to reproduce: a long message wrapped in bold text code is never truncated in mod_kunenalatest.
The original NBBC code should have used $text instead of $this->text. I'll make a PR for it.
But the guessTextLength() issue is real. Since the PHP 8.5 workaround, the state never goes back to TEXT after the first tag, so only the text before the first tag is counted. Easy to reproduce: a long message wrapped in bold text code is never truncated in mod_kunenalatest.
The original NBBC code should have used $text instead of $this->text. I'll make a PR for it.
Please Log in or Create an account to join the conversation.
2 days 2 hours ago #235699
by guidocx84
Replied by guidocx84 on topic Possible Bug in BBCodeLexer::guessTextLength() causes mod_kunenalatest issue
Thanks for the clarification and for looking into the
issue.I've now confirmed that the fix we discussed resolves the truncation problem:
correctly respects the 150-character limit, even when the message contains BBCode.However, while testing, I noticed a separate issue in
.The current quote-removal regex is:
As it uses a non-greedy match, it stops at the first closing
tag. When a message contains nested quotes, it therefore removes only part of the quoted content and leaves the reply inside the outer quote.For example, with this structure:
leaves B's reply in the text, so Kunena Latest displays "Reply by B" instead of only A's final reply.I tested the following replacement in my TEST environment:
This correctly removes the entire outer quote, including all nested quotes, and leaves only the final reply. I've verified that it works with the original message that exposed the issue.So, in addition to the
bug, there seems to be another issue worth addressing in
: nested quote removal.Thanks again for your work on Kunena!
Code:
guessTextLength()
Code:
mod_kunenalatest
Code:
KunenaParser::stripBBCode()
Code:
$txt = preg_replace('/\[quote(.*?)\](.*?)\[\/quote\]/s', '', $txt);
Code:
[/quote]
Code:
[quote="B"]
[quote="A"]
Original message by A
[/quote]
Reply by B
[/quote]
Final reply by A
Code:
stripBBCode()
Code:
$txt = preg_replace('~\[quote\b[^\]]*\](?:(?R)|\[(?!/?quote\b)[^\]]*\]|[^\[])*\[/quote\]~is', '', $txt);
Code:
guessTextLength()
Code:
stripBBCode()
Please Log in or Create an account to join the conversation.
Time to create page: 0.111 seconds