Overview
Comment:Fix LIKE handling to be correct for "begins with" and "ends with" LIKEs, see [28fc79a800036f41]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: e214118d85a5019f2cd5181a25222b69cadf103799c8e5ff7ae2d26b688e3089
User & Date: bohwaz on 2021-07-24 15:03:03
Other Links: manifest | tags
Context
2021-07-24
15:25
Add date choice to payment form, as requested by @Pierrick check-in: e6ea5d218d user: bohwaz tags: trunk, stable
15:03
Fix LIKE handling to be correct for "begins with" and "ends with" LIKEs, see [28fc79a800036f41] check-in: e214118d85 user: bohwaz tags: trunk, stable
2021-07-16
17:38
Fix update when non-official directories exist in the files storage check-in: 578805a539 user: bohwaz tags: trunk, stable, 1.1.10
Changes

Modified src/include/lib/Garradin/DB.php from [7ce0e3f7d3] to [0f64109cbd].

208
209
210
211
212
213
214
215
216

217
218

219














220
221
222
223
224
225
226
227
228
     * @see https://www.sqlite.org/c3ref/strlike.html
     * @see https://sqlite.org/src/file?name=ext/icu/icu.c&ci=trunk
     */
    static public function unicodeLike($pattern, $value, $escape = null) {
        $id = md5($pattern . $escape);

        if (!array_key_exists($id, self::$unicode_patterns_cache)) {
            $pattern = Utils::unicodeCaseFold($pattern);
            $escape = $escape ? '(?!' . preg_quote($escape, '/') . ')' : '';

            $pattern = preg_quote($pattern, '/');
            $pattern = preg_replace('/' . $escape . '%/', '.*', $pattern);

            $pattern = preg_replace('/' . $escape . '_/', '.', $pattern);














            $pattern = '/' . $pattern . '/';
            self::$unicode_patterns_cache[$id] = $pattern;
        }

        $value = Utils::unicodeCaseFold($value);

        return (bool) preg_match(self::$unicode_patterns_cache[$id], $value);
    }
}







<

>
|
<
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|








208
209
210
211
212
213
214

215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
     * @see https://www.sqlite.org/c3ref/strlike.html
     * @see https://sqlite.org/src/file?name=ext/icu/icu.c&ci=trunk
     */
    static public function unicodeLike($pattern, $value, $escape = null) {
        $id = md5($pattern . $escape);

        if (!array_key_exists($id, self::$unicode_patterns_cache)) {

            $escape = $escape ? '(?!' . preg_quote($escape, '/') . ')' : '';
            preg_match_all('/('.$escape.'[%_])|(\w+)|(.+?)/iu', $pattern, $parts, PREG_SET_ORDER);
            $pattern = '';


            foreach ($parts as $part) {
                if (isset($part[3])) {
                    $pattern .= preg_quote($part[0], '/');
                }
                elseif (isset($part[2])) {
                    $pattern .= Utils::unicodeCaseFold($part[2]);
                }
                elseif ($part[1] == '%') {
                    $pattern .= '.*';
                }
                elseif ($part[1] == '_') {
                    $pattern .= '.';
                }
            }

            $pattern = '/^' . $pattern . '$/i';
            self::$unicode_patterns_cache[$id] = $pattern;
        }

        $value = Utils::unicodeCaseFold($value);

        return (bool) preg_match(self::$unicode_patterns_cache[$id], $value);
    }
}