pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: stephane.campinas@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16236: Invalid escape encoding
Date: Mon, 27 Jan 2020 18:05:45 -0500
Message-ID: <25295.1580166345@sss.pgh.pa.us> (raw)
In-Reply-To: <16236-887912799bb3eb3c@postgresql.org>
References: <16236-887912799bb3eb3c@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> From the documentation [0] about the encode function, the "escape" format
> should "convert zero bytes and high-bit-set bytes to octal sequences (\nnn)
> and doubles backslashes."
> However, executing "select encode(E'aaa\bccc', 'escape');" outputs
> "aaa\x08ccc", although according to the documentation I should get
> "aaa\010ccc".

No, I don't think so.  The \b gives rise to a byte with hex value 08
(that is, control-H or backspace) in the E'' literal, which converts
to the same byte value in the bytea value that gets passed to
encode().  Since that's not either a zero or a high-bit-set value,
encode() just repeats it literally in the text result, and you end
up with the same thing as if you'd just done

=# select E'aaa\bccc'::text;     
    text    
------------
 aaa\x08ccc
(1 row)

I think it must be psql itself that's choosing to represent the
backspace as \x08, because nothing in the backend does that.
(pokes around ... yeah, it's pg_wcsformat() that's doing it)

You could certainly make an argument that encode() ought to
backslashify all ASCII control characters, not only \0.  But
it's behaving as documented, AFAICS.

			regards, tom lane





view thread (4+ messages)  latest in thread

Message-ID: <25295.1580166345@sss.pgh.pa.us>
Permalink:  ../25295.1580166345@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25295.1580166345@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, stephane.campinas@gmail.com
  Subject: Re: BUG #16236: Invalid escape encoding
  In-Reply-To: <25295.1580166345@sss.pgh.pa.us>
  References: <16236-887912799bb3eb3c@postgresql.org> <25295.1580166345@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox