• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed Redundant preg_match calls in XenForo_BbCode_Parser

Xon

Well-known member
#1
In XenForo_BbCode_Parser::_parseTagOpen there is:

Code:
if (strlen($tagName) == 0 || preg_match('/[^a-z0-9_-]/i', $tagName) || !$this->_getTagRule($tagName))
{
    return false;
}
I'm fairly sure that the call preg_match isn't required as _getTagRule will do a fast isset lookup into the taglist, This tag list has already been verified that the tag names match that pattern anyway.

In XenForo_BbCode_Parser::_parseTagClose:

Code:
if (strlen($tagName) == 0 || preg_match('/[^a-z0-9_-]/i', $tagName))
If this isn't a valid tag, then it can't be considered to be a closing tag. So that preg_match could be replaced with a call to _getTagRule.

IMO the length check could be pushed into _getTagRule (and adding a check that the tag name isn't longer than 25 character) before the strtolower call is even done.
 
Last edited:

Mike

XenForo developer
Staff member
#2
I've changed this now, though I don't think there's really any effective difference (likely close to negligible performance differences I think, assuming tag names are short).

I would hesitate to put an explicit length limit in right now, as there may be situations where longer tags have been used (though I hope not).