[3.5.x] Fix broken safe_open() when path contains double slashes.

(cherry picked from commit ed36f31a54950a2778f380a9c3606502120ba647)