From 1f96a2c79a61ab7c348103a1d4530aa0b85976f0 Mon Sep 17 00:00:00 2001
From: LukeWCS <luke@wcsaga.org>
Date: Wed, 1 Feb 2023 20:21:37 +0100
Subject: [PATCH] [ticket/17076] Fix signature length calculation

The error occurs when BBcode is used but there is no whitespace. In this case,
a part of the RegEx that is designed to be greedy is responsible for selecting
all BBcode tag containers and their content that do not contain whitespace.
This, in combination with the replace string, effectively reduces the entire
signature to a single space. This is the explanation for the reported behavior
of phpBB.

In addition, the bug also generally prevents the correct removal of BBcode
containers if their content does not contain whitespace. In such cases, the
BBcode tags are removed along with the content, which also results in
incorrect calculation of the text length.

* Changed the corresponding RegEx part from greedy to non-greedy.
* Removed an unnecessary class definition.
* Changed an unnecessary capturing group to a non-capturing group.
* Changed the replace string from a space to an empty string. <- Here,
however, I'm not sure if the space was intentional or not!

PHPBB3-17076
---
 phpBB/includes/message_parser.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 91c50cfe5a..6c8984fa82 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -1154,7 +1154,7 @@ class parse_message extends bbcode_firstpass
 		}
 
 		// Store message length...
-		$message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message));
+		$message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(?:=\S+?)?\]#ius', '', $this->message));
 
 		// Maximum message length check. 0 disables this check completely.
 		if ((int) $config['max_' . $mode . '_chars'] > 0 && $message_length > (int) $config['max_' . $mode . '_chars'])