Missing LIKE escaping on search string in User/Search/Gambit/FulltextGambit
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Bug Report
**Current Behavior**
Currently if I do a search for `%%%` in the search bar, it matches all the users. This is because `%` and `_` are wildcards in the `LIKE` queries.
**Steps to Reproduce**
1. Go to 'https://discuss.flarum.org/'
2. Search for `%%%`
3. Wait a second and see a list of the first 5 users that matched.
**Expected Behavior**
I wouldn't expect any users to match.
**Screenshots**

**Environment**
- Flarum version: v0.1.0-beta.16
- Website URL: any
- Webserver: any
- Hosting environment: any
- PHP version: all
- Browser: all
```
$ php flarum info
Flarum core 0.1.0-beta.16
PHP version: 7.4.16
Loaded extensions: Core, date, libxml, openssl, pcre, sqlite3, zlib, ctype, curl, dom, fileinfo, filter, ftp, hash, iconv, json, mbstring, SPL, PDO, session, posix, readline, Reflection, standard, SimpleXML, pdo_sqlite, Phar, tokenizer, xml, xmlreader, xmlwriter, mysqlnd, bcmath, exif, gd, mysqli, pdo_mysql, sodium, zip, Zend OPcache
+-------------------------+------------------+------------------------------------------+
| Flarum Extensions | | |
+-------------------------+------------------+------------------------------------------+
| ID | Version | Commit |
+-------------------------+------------------+------------------------------------------+
| flarum-flags | v0.1.0-beta.16 | |
| flarum-tags | v0.1.0-beta.16 | |
| flarum-suspend | v0.1.0-beta.16 | |
| flarum-subscriptions | v0.1.0-beta.16 | |
| flarum-sticky | v0.1.0-beta.16 | |
| flarum-statistics | v0.1.0-beta.16 | |
| flarum-mentions | v0.1.0-beta.16 | |
| flarum-markdown | v0.1.0-beta.16.1 | |
| flarum-lock | v0.1.0-beta.16 | |
| flarum-likes | v0.1.0-beta.16 | |
| flarum-lang-english | v0.1.0-beta.16 | |
| flarum-emoji | v0.1.0-beta.16 | |
| flarum-bbcode | v0.1.0-beta.16 | |
| flarum-approval | v0.1.0-beta.16 | |
+-------------------------+------------------+------------------------------------------+
Base URL: https://localhost/forum
Installation path: /var/www/html/forum
Debug mode: ON
Don't forget to turn off debug mode! It should never be turned on in a production system.
```
**Possible Solution**
See these functions where the string simply has the `%` appended without escaping the string first.
https://github.com/flarum/core/blob/023871ef86d436cc14631ee63cbbfd3ef9fd4bf1/src/User/Search/Gambit/FulltextGambit.php#L35-L53
These functions on the other hand do escape the value first.
https://github.com/flarum/core/blob/46794483005b03455ceb128acfd057c26fa4639f/src/User/UserRepository.php#L106-L142
Contributor guide
Research direction
Start with src/User/Search/Gambit/FulltextGambit.php at the linked search functions, then compare their handling with the escaping in src/User/UserRepository.php. Reproduce a search for `%%%` and verify that wildcard characters are treated literally rather than matching the first users; check the surrounding search behavior before finalizing the change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100