pgsql: Handle empty-string edge cases correctly in strpos().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Handle empty-string edge cases correctly in strpos().
Date: 2019-10-28 16:21:21
Message-ID: E1iP7lh-0002LQ-7B@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Handle empty-string edge cases correctly in strpos().

Commit 9556aa01c rearranged the innards of text_position() in a way
that would make it not work for empty search strings. Which is fine,
because all callers of that code special-case an empty pattern in
some way. However, the primary use-case (text_position itself) got
special-cased incorrectly: historically it's returned 1 not 0 for
an empty search string. Restore the historical behavior.

Per complaint from Austin Drenski (via Shay Rojansky).
Back-patch to v12 where it got broken.

Discussion: https://postgr.es/m/CADT4RqAz7oN4vkPir86Kg1_mQBmBxCp-L_=9vRpgSNPJf0KRkw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/bd1ef5799b04168d8a869197dd9b85935d5d5da9

Modified Files
--------------
src/backend/utils/adt/varlena.c | 10 +++++++++-
src/test/regress/expected/strings.out | 18 ++++++++++++++++++
src/test/regress/sql/strings.sql | 6 ++++++
3 files changed, 33 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2019-10-28 18:15:08 pgsql: On Windows, use COMSPEC to find the location of cmd.exe.
Previous Message Michael Paquier 2019-10-28 05:24:44 pgsql: Doc: Add missing step for pg_stat_progress_cluster