The loop in MatchText() processed a leading '\' without regard to nondeterministic locales, which is problematic if what the '\' precedes is an ordinary character that should be subject to nondeterministic matching. We'd insist on a literal match for it, which is not right and is not like what happens with a '\' that follows some ordinary characters. Worse, we'd then advance the text and pattern pointers by one byte, so that if the escaped character is multibyte the next loop iteration would take the nondeterministic code path starting at a point within the character. That could very possibly cause pg_strncoll() to misbehave. The fix is quite simple: move the stanza that handles '\' down past the one that handles nondeterminism. The stanzas for '%' and '_' are fine where they are, but the '\' stanza is only correct for deterministic matching. The logic for nondeterministic cases is already prepared to do the right things with a '\'. While here, I replaced tests of "locale && !locale->deterministic" with a boolean local variable, reasoning that those are in the hot loop paths so saving a branch and indirect fetch is worth the trouble. I also improved a number of related comments. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/391592.1783187986@sss.pgh.pa.us Backpatch-through: 18 |
||
|---|---|---|
| .github | ||
| config | ||
| contrib | ||
| doc | ||
| src | ||
| .dir-locals.el | ||
| .editorconfig | ||
| .git-blame-ignore-revs | ||
| .gitattributes | ||
| .gitignore | ||
| .mailmap | ||
| aclocal.m4 | ||
| configure | ||
| configure.ac | ||
| COPYRIGHT | ||
| GNUmakefile.in | ||
| HISTORY | ||
| Makefile | ||
| meson.build | ||
| meson_options.txt | ||
| README.md | ||
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.