Commit 90ea3bf9 authored by Max Kellermann's avatar Max Kellermann

playlist/Song: support backslash in relative URIs

parent 83b08712
ver 0.21.12 (not yet released)
* Windows
- support backslash in relative URIs loaded from playlists
ver 0.21.11 (2019/07/03)
* input
......
......@@ -66,6 +66,22 @@ playlist_check_translate_song(DetachedSong &song, const char *base_uri,
base_uri = nullptr;
const char *uri = song.GetURI();
#ifdef _WIN32
if (!PathTraitsUTF8::IsAbsolute(uri) && strchr(uri, '\\') != nullptr) {
/* Windows uses the backslash as path separator, but
the MPD protocol uses the (forward) slash by
definition; to allow backslashes in relative URIs
loaded from playlist files, this step converts all
backslashes to (forward) slashes */
std::string new_uri(uri);
std::replace(new_uri.begin(), new_uri.end(), '\\', '/');
song.SetURI(std::move(new_uri));
uri = song.GetURI();
}
#endif
if (base_uri != nullptr && !uri_has_scheme(uri) &&
!PathTraitsUTF8::IsAbsolute(uri))
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
......
......@@ -270,3 +270,23 @@ TEST_F(TranslateSongTest, Relative)
insecure_loader));
EXPECT_EQ(se, ToString(song4));
}
TEST_F(TranslateSongTest, Backslash)
{
const SongLoader loader(reinterpret_cast<const Database *>(1),
storage);
DetachedSong song1("foo\\bar.ogg", MakeTag2b());
#ifdef _WIN32
/* on Windows, all backslashes are converted to slashes in
relative paths from playlists */
auto se = ToString(DetachedSong(uri2, MakeTag2c()));
EXPECT_TRUE(playlist_check_translate_song(song1, nullptr,
loader));
EXPECT_EQ(se, ToString(song1));
#else
/* backslash only supported on Windows */
EXPECT_FALSE(playlist_check_translate_song(song1, nullptr,
loader));
#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