TextFormat: do not assume that an array given to toHTML() is actually a tokenized string

this is a far stretch, since the documentation doesn't mention that the string needs to be tokenized. Anyone passing an array in here is most likely doing so by mistake.
This commit is contained in:
Dylan K. Taylor
2021-08-12 23:37:00 +01:00
parent a59ac522ee
commit 34309bc810

View File

@ -159,16 +159,11 @@ abstract class TextFormat{
/**
* Returns an HTML-formatted string with colors/markup
*
* @param string|string[] $string
*/
public static function toHTML($string) : string{
if(!is_array($string)){
$string = self::tokenize($string);
}
public static function toHTML(string $string) : string{
$newString = "";
$tokens = 0;
foreach($string as $token){
foreach(self::tokenize($string) as $token){
switch($token){
case TextFormat::BOLD:
$newString .= "<span style=font-weight:bold>";