Re: Invisible PROMPT2
| От | Thomas Munro |
|---|---|
| Тема | Re: Invisible PROMPT2 |
| Дата | |
| Msg-id | CA+hUKGL23CGmnno5TztLd58Dtat5QHKzA0F72Pkv+J4TSjgu4A@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Invisible PROMPT2 (Tom Lane <tgl@sss.pgh.pa.us>) |
| Ответы |
Re: Invisible PROMPT2
|
| Список | pgsql-hackers |
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.
Вложения
В списке pgsql-hackers по дате отправления: