This reverts commit 3a66035107. A regression test was also added. Backport of d63ac5b595 from master.
3a66035107
d63ac5b595