Resolve paths properly for Windows

This is non-trivial because paths in Windows may contain backslashes,
and the drive may be misinterpreted as a URI scheme. This commit also
simplifies the logic of handling fragments ("#") in URIs.