BBcode tag validation events

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
b_gravedigger
Registered User
Posts: 3
Joined: Sat Nov 16, 2013 9:33 pm

BBcode tag validation events

Post by b_gravedigger »

Hello all.

I recenty encountered a problem with greek characters in links inside URL tags (i.e. http://γιατρος.gr). After a bit of digging around i found out that the previous link is considered invalid due to the regex used in functions.php for validating urls. So i thought it would be a good idea to have events capable of modifying various bbcode validations, such as urls.

For example, by adding an event such as

Code: Select all

/**
* Event to add extra validations to url bbcode tag
*
* @event core.add_extra_validations_to_url
* @var valid   check for validity
* @url         url to validate
* @since 3.1.0-a3
*/
$vars = array('url','valid');
extract($phpbb_dispatcher->trigger_event('core.add_extra_validations_to_url', compact($vars)));   
to the validate_url function of message_parser.php, i can then use a listener such as

Code: Select all

class main_listener implements EventSubscriberInterface
{

    static public function getSubscribedEvents()
    {
        return array(
            'core.add_extra_validations_to_url' => 'allow_greek_in_url_bbcode',
        );
    }
   
    public function allow_greek_in_url_bbcode($event)
    {
         if(!$event['valid'])
         	if (preg_match("#^[a-z][a-z\d+\-.]*:/{2}(?:(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@|]+|%[\dA-F]{2})+|[0-9.]+|\[[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς.]+:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς.]+:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς.:]+\])(?::\d*)?(?:/(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?$#i", $event['url']) ||
					preg_match("#^www\.(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@|]+|%[\dA-F]{2})+(?::\d*)?(?:/(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9a-z0-Α-Ωα-ωΪΫάέήίΰϊϋόύώς\-._~!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?$#i", $event['url']))
				{
               $event['valid'] = true;
            }
   }
}
to revalidate a rejected url based on my custom rules (in this case i just added greek characters to the default regex). It's probably not the most elegant way of solving the problem, but i think the whole idea is worth a discussion, at least.

:)

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: BBcode tag validation events

Post by EXreaction »

We plan on replacing the BBCode system for 3.2, so these events wouldn't exist for very long. Hopefully this will be fixed with the new parser we use, although I've not looked into that.

b_gravedigger
Registered User
Posts: 3
Joined: Sat Nov 16, 2013 9:33 pm

Re: BBcode tag validation events

Post by b_gravedigger »

Thanks for your reply. Awaiting the new parser then.

User avatar
JoshyPHP
Registered User
Posts: 381
Joined: Fri Jul 08, 2011 9:43 pm

Re: BBcode tag validation events

Post by JoshyPHP »

EXreaction wrote:We plan on replacing the BBCode system for 3.2, so these events wouldn't exist for very long. Hopefully this will be fixed with the new parser we use, although I've not looked into that.
URLs are validated via PHP's ext/filter. Internationalized Domain Names are punycoded if idn_to_ascii() is available. Non-ASCII characters are percent-encoded. ext/filter doesn't support non-ASCII URLs so if you don't have idn_to_ascii() URLs with an IDN end up being rejected. The RFC has links to the relevant issues in the tracker and to the corresponding tests.

Post Reply