Kirapwn 4718

This is a rebased and squashed PR that replaces: https://github.com/joomla/joomla-cms/pull/4718 that fixes #4551 

I just added 2 small code style fixes so tests should still apply and it should be RTC.