diff --git a/CHANGELOG.md b/CHANGELOG.md index 56c66d15..1cfe581b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). -## [Unreleased] +## [3.1.2] - 2022-06-04 ### Added * *Nothing* @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ### Fixed * [#1448](https://github.com/shlinkio/shlink/issues/1448) Fixed HTML entities not being properly parsed when auto-resolving page titles. +* [#1458](https://github.com/shlinkio/shlink/issues/1458) Fixed 500 error when filtering short URLs by ALL tags and search term. ## [3.1.1] - 2022-05-09 diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index 9852c530..d16d9993 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -102,15 +102,22 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU $qb->leftJoin('s.tags', 't'); } - // Apply search conditions + // Apply general search conditions + $conditions = [ + $qb->expr()->like('s.longUrl', ':searchPattern'), + $qb->expr()->like('s.shortCode', ':searchPattern'), + $qb->expr()->like('s.title', ':searchPattern'), + $qb->expr()->like('d.authority', ':searchPattern'), + ]; + + // Apply tag conditions, only when not filtering by all provided tags + $tagsMode = $filtering->tagsMode() ?? ShortUrlsParams::TAGS_MODE_ANY; + if (empty($tags) || $tagsMode === ShortUrlsParams::TAGS_MODE_ANY) { + $conditions[] = $qb->expr()->like('t.name', ':searchPattern'); + } + $qb->leftJoin('s.domain', 'd') - ->andWhere($qb->expr()->orX( - $qb->expr()->like('s.longUrl', ':searchPattern'), - $qb->expr()->like('s.shortCode', ':searchPattern'), - $qb->expr()->like('s.title', ':searchPattern'), - $qb->expr()->like('t.name', ':searchPattern'), - $qb->expr()->like('d.authority', ':searchPattern'), - )) + ->andWhere($qb->expr()->orX(...$conditions)) ->setParameter('searchPattern', '%' . $searchTerm . '%'); } diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index 4ad89629..c67ff34b 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -128,6 +128,12 @@ class ShortUrlRepositoryTest extends DatabaseTestCase self::assertEquals(1, $this->repo->countList(new ShortUrlsCountFiltering('foo', ['bar']))); self::assertSame($foo, $result[0]); + // Assert searched text also applies to tags + $result = $this->repo->findList(new ShortUrlsListFiltering(null, null, Ordering::emptyInstance(), 'bar')); + self::assertCount(2, $result); + self::assertEquals(2, $this->repo->countList(new ShortUrlsCountFiltering('bar'))); + self::assertContains($foo, $result); + $result = $this->repo->findList(new ShortUrlsListFiltering(null, null, Ordering::emptyInstance())); self::assertCount(3, $result);