[ticket/12097] Bug fix and adding unit test

PHPBB3-12097