]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Improve reporting of invalid weight symbols in setweight() et al.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 4 Jun 2026 16:24:51 +0000 (12:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 4 Jun 2026 16:24:51 +0000 (12:24 -0400)
commit262cc4df28976622aed47239c66f0bf56b1ce7bf
tree349c318da6a966b5ac5416fe0aa12428ca5e9228
parent7bdff3e890e3d1149e9753b61667ccd14f15e6f4
Improve reporting of invalid weight symbols in setweight() et al.

This commit addresses two related issues:

tsvector_filter() assumed it could print an incorrect weight value
with %c.  This could result in an invalidly-encoded error message
if the database encoding is multibyte and the char value has its
high bit set.  Weight values that are ASCII control characters
could render illegibly too.  Fix by printing such values in octal
(\ooo), similarly to how charout() would render them.

tsvector_setweight() and tsvector_setweight_by_filter() reported
the same unrecognized-weight error condition with elog(), as though
it were an internal error.  That'd not translate, would produce an
unwanted XX000 SQLSTATE code, and also reported the bad value as a
decimal integer which seems unhelpful.  Fix by refactoring so that
all three functions share one copy of the code that interprets a
weight argument.

The invalid-encoding aspect seems to me (tgl) to justify
back-patching.

Author: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAON2xHNaeLAUzRCXL5AmXLcXaSE_gWAVjWQRmLzc_oZ=1_Vf4Q@mail.gmail.com
Backpatch-through: 14
src/backend/utils/adt/tsvector_op.c