Fixes for BUG-12161

Fix and unit test to resolve [Bug 12161](http://bugs.horde.org/ticket/12161)