Applied PR upstream after adding a test case. Gail Badner, you might want to port it on 5.1 and 5.0 too.