Re: Invisible PROMPT2
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>,
Kyotaro Horiguchi <horikyota.ntt@gmail.com>, David Fetter <david@fetter.org>, ilmari@ilmari.org, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2019-11-18T21:07:33Z
Lists: pgsql-hackers
Attachments
- v2-0001-Allow-invisible-PROMPT2-in-psql.patch (application/octet-stream) patch v2-0001
On Tue, Nov 19, 2019 at 6:21 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Thomas Munro <thomas.munro@gmail.com> writes: > > Yeah. Maybe pg_wcswidth() would be OK though, and it's available in > > psql, though I guess you'd have to make a copy with the escaped bits > > stripped out. > > Right, you should use pg_wcswidth() or the underlying PQdsplen() function > to compute display width. The latter might be more convenient since > you could apply it character by character rather than making a copy > of the string. Right, a PQdsplen()/PQmblen() loop works nicely, as attached. I spotted a potential problem: I suppose I could write a PROMPT1 that includes an invalid multibyte sequence at the end of the buffer and trick PQmblen() or PQdsplen() into reading a few bytes past the end. Two defences against that would be (1) use pg_encoding_verifymb() instead of PQmblen() and (2) use pg_encoding_max_length() to make sure you can't get close enough to the end of the buffer, but neither of those functions are available to psql.
Commits
-
psql: Fix %w length in PROMPT2 when PROMPT1 contains a newline.
- 1713a0013f90 13.0 landed
-
Allow invisible PROMPT2 in psql.
- 7f338369ca62 13.0 landed