Apply Christian Hammerl's fix for tickets 9683 and 10187. Supply test cases that should work for both POSIX and Windows. Tested with fix commented out to verify test cases do detect the problem.