Based on a patch by Hacene Bouaroua. Fixes ticket #11171. Co-authored-by: Hacene Bouaroua <hbouaroua@freebox.fr> Signed-off-by: James Almer <jamrial@gmail.com>