Skip to content

SQL LIKE comparisons in SQLite: Escaping doesn't work #8090

@marcelklehr

Description

@marcelklehr

Steps to reproduce

  1. Install bookmarks app (I believe the bug lies much deeper, but I'll demonstrate it with a concrete example. It's probably pretty easy to adapt the steps here to utilize other database entries/tables)
  2. Add two bookmarks, edit the first one's title to read foo_ and the second one's fooo

Variant 1:
Run:

$title = 'foo_';
$qb = $c->query('ServerContainer')->getDatabaseConnection()->getQueryBuilder();
$qb->select('title');
$qb
    ->from('bookmarks', 'b')
    ->where($qb->expr()->iLike('b.title', $qb->createNamedParameter('%'.$this->db->escapeLikeParameter($title).'%')););
$results = $qb->execute()->fetchAll();
assert(count($results) === 1); // fails, $results is empty

Variant 2:

$title = 'foo_';
$qb = $c->query('ServerContainer')->getDatabaseConnection()->getQueryBuilder();
$qb->select('title');
$qb
    ->from('bookmarks', 'b')
    ->where($qb->expr()->iLike('b.title', $qb->createNamedParameter('%'.$title.'%')););
$results = $qb->execute()->fetchAll();
assert(count($results) === 1) // fails, $results is now 2

Originally I stumbled onto this in nextcloud/bookmarks#432

Server configuration

Operating system: Ubuntu

Web server: apache2

Database: SQLite

PHP version: 7.1.8

Nextcloud version: 12.0.2

Updated from an older Nextcloud/ownCloud or fresh install: fresh install

Where did you install Nextcloud from: docker

Signing status:

Signing status
No errors have been found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagePending check for reproducibility or if it fits our roadmapbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions