Commit 18602f8b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Search: Reject patterns too short

parent 367dfaab
...@@ -150,6 +150,11 @@ bool MediaLibrary::createAllTables() ...@@ -150,6 +150,11 @@ bool MediaLibrary::createAllTables()
return true; return true;
} }
bool MediaLibrary::validateSearchPattern( const std::string& pattern )
{
return pattern.size() >= 3;
}
bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* mlCallback ) bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* mlCallback )
{ {
if ( m_fsFactory == nullptr ) if ( m_fsFactory == nullptr )
...@@ -407,16 +412,22 @@ std::vector<HistoryPtr> MediaLibrary::history() const ...@@ -407,16 +412,22 @@ std::vector<HistoryPtr> MediaLibrary::history() const
std::vector<MediaPtr> MediaLibrary::searchAlbumTracks( const std::string& title ) const std::vector<MediaPtr> MediaLibrary::searchAlbumTracks( const std::string& title ) const
{ {
if ( validateSearchPattern( title ) == false )
return {};
return AlbumTrack::search( m_dbConnection.get(), title ); return AlbumTrack::search( m_dbConnection.get(), title );
} }
std::vector<PlaylistPtr> MediaLibrary::searchPlaylists( const std::string& name ) const std::vector<PlaylistPtr> MediaLibrary::searchPlaylists( const std::string& name ) const
{ {
if ( validateSearchPattern( name ) == false )
return {};
return Playlist::search( m_dbConnection.get(), name ); return Playlist::search( m_dbConnection.get(), name );
} }
std::vector<AlbumPtr> MediaLibrary::searchAlbums( const std::string& pattern ) const std::vector<AlbumPtr> MediaLibrary::searchAlbums( const std::string& pattern ) const
{ {
if ( validateSearchPattern( pattern ) == false )
return {};
return Album::search( m_dbConnection.get(), pattern ); return Album::search( m_dbConnection.get(), pattern );
} }
......
...@@ -119,6 +119,7 @@ class MediaLibrary : public IMediaLibrary ...@@ -119,6 +119,7 @@ class MediaLibrary : public IMediaLibrary
virtual void startDiscoverer(); virtual void startDiscoverer();
bool updateDatabaseModel( unsigned int previousVersion ); bool updateDatabaseModel( unsigned int previousVersion );
bool createAllTables(); bool createAllTables();
static bool validateSearchPattern( const std::string& pattern );
protected: protected:
std::unique_ptr<SqliteConnection> m_dbConnection; std::unique_ptr<SqliteConnection> m_dbConnection;
......
...@@ -124,7 +124,7 @@ TEST_F( AlbumTracks, Search ) ...@@ -124,7 +124,7 @@ TEST_F( AlbumTracks, Search )
auto tracks = ml->searchAlbumTracks( "tra" ); auto tracks = ml->searchAlbumTracks( "tra" );
ASSERT_EQ( 10u, tracks.size() ); ASSERT_EQ( 10u, tracks.size() );
tracks = ml->searchAlbumTracks( "1" ); tracks = ml->searchAlbumTracks( "track 1" );
ASSERT_EQ( 2u, tracks.size() ); ASSERT_EQ( 2u, tracks.size() );
tracks = ml->searchAlbumTracks( "grouik" ); tracks = ml->searchAlbumTracks( "grouik" );
......
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