Commit 602b348d authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

utils: win32: Always use backward slashes for path, forward for mrls

(cherry picked from commit 89d87acf)
Signed-off-by: 's avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 5fccc43c
...@@ -198,14 +198,17 @@ std::string toLocalPath( const std::string& mrl ) ...@@ -198,14 +198,17 @@ std::string toLocalPath( const std::string& mrl )
// DIR_SEPARATOR_CHAR here. // DIR_SEPARATOR_CHAR here.
if ( path[0] == '/' && isalpha( path[1] ) ) if ( path[0] == '/' && isalpha( path[1] ) )
path.erase( 0, 1 ); path.erase( 0, 1 );
std::replace( begin( path ), end( path ), '/', '\\' );
return utils::url::decode( path ); return utils::url::decode( path );
} }
std::string toMrl( const std::string& path ) std::string toMrl( const std::string& path )
{ {
auto normalized = path;
std::replace( begin( normalized ), end( normalized ), '\\', '/' );
return std::string{ "file://" } + return std::string{ "file://" } +
( isalpha( path[0] ) ? "/" : "" ) + ( isalpha( normalized[0] ) ? "/" : "" ) +
utils::url::encode( path ); utils::url::encode( normalized );
} }
#endif #endif
......
...@@ -122,10 +122,10 @@ TEST( FsUtils, toLocalPath ) ...@@ -122,10 +122,10 @@ TEST( FsUtils, toLocalPath )
ASSERT_EQ( "/tést/ßóíú/file", utils::file::toLocalPath( "file:///t%C3%A9st/%C3%9F%C3%B3%C3%AD%C3%BA/file" ) ); ASSERT_EQ( "/tést/ßóíú/file", utils::file::toLocalPath( "file:///t%C3%A9st/%C3%9F%C3%B3%C3%AD%C3%BA/file" ) );
ASSERT_EQ( "/&/#/~", utils::file::toLocalPath( "file:///%26/%23/%7E" ) ); ASSERT_EQ( "/&/#/~", utils::file::toLocalPath( "file:///%26/%23/%7E" ) );
#else #else
ASSERT_EQ( "a/b/c/movie.avi", utils::file::toLocalPath( "file:///a/b/c/movie.avi" ) ); ASSERT_EQ( "a\\b\\c\\movie.avi", utils::file::toLocalPath( "file:///a/b/c/movie.avi" ) );
ASSERT_EQ( "x/yea /sp ace", utils::file::toLocalPath( "file:///x/yea%20/sp%20ace" ) ); ASSERT_EQ( "x\\yea \\sp ace", utils::file::toLocalPath( "file:///x/yea%20/sp%20ace" ) );
ASSERT_EQ( "d/tést/ßóíú/file", utils::file::toLocalPath( "file:///d/t%C3%A9st/%C3%9F%C3%B3%C3%AD%C3%BA/file" ) ); ASSERT_EQ( "d\\tést\\ßóíú\\file", utils::file::toLocalPath( "file:///d/t%C3%A9st/%C3%9F%C3%B3%C3%AD%C3%BA/file" ) );
ASSERT_EQ( "c/&/#/~", utils::file::toLocalPath( "file:///c/%26/%23/%7E" ) ); ASSERT_EQ( "c\\&\\#\\~", utils::file::toLocalPath( "file:///c/%26/%23/%7E" ) );
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment