Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3kh0-0006EX-CW for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Mar 2019 16:55:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3kgy-00040U-Fy for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Mar 2019 16:55:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3jSV-00021Y-O3 for pgsql-bugs@lists.postgresql.org; Tue, 12 Mar 2019 15:36:51 +0000 Received: from cowfish.bmrb.wisc.edu ([144.92.167.220] helo=mail.bmrb.wisc.edu) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3jSR-0000x2-Mh for pgsql-bugs@lists.postgresql.org; Tue, 12 Mar 2019 15:36:50 +0000 Received: from manowar.bmrb.wisc.edu (unknown [144.92.167.189]) by mail.bmrb.wisc.edu (Postfix) with ESMTP id 3C877FA06C0; Tue, 12 Mar 2019 10:36:45 -0500 (CDT) To: pgsql-bugs@lists.postgresql.org From: Jon Wedell Subject: Bug involving plus sign before newline in text field being duplicated or stripped Openpgp: preference=signencrypt Autocrypt: addr=wedell@bmrb.wisc.edu; prefer-encrypt=mutual; keydata= mQENBFObWdsBCAC7rB6DsWf51yupZmjHi0XQuG3vo4aTpSKsO6zZwfi/LjUYSoofbW2+qVxK NjLUgRyB1G1lWSM93zmvNTS25O9SD3i3dCHNpGP5L0K4I/QE/djE3vYM0c9BjTo3x5m6brpp fROhvNTOWKpHV7wUaV6d8sX6JEIefr85y7l+8SnCTvKH7vX4GvaWvwzaIKtAsv5ISGX41JNf Yi+s99/iE+fAVSbZpRB2f1sL1GF8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2xLWkG0NTtLJZ80DcBGlxvBFnIt8v3xya9cP9nuwM3JIf0x36RCiyvPcC 5AJRK9qrS/YCSYOHQ2pvex0+84WadfE04qKkFAc989e/e8i3NZ+3Sm++dYVQ533L0WmGym6X f2hN6UDosgNP8QvorSdNJOoyALKRYXLmulIhgCRUSavbIptYcsCndRgq23zLwkjN8PebNKWS nAVWbcUqY24ilkgyAJAdRnZjQRy6o4EXdgMaienDlPGjUe+nPBlZQWDtLsLIkvFFlMRyWPyK minZxuJcPMQ= Cc: Dimitri Maziuk Message-ID: <7ccaa770-ef82-42bf-dd56-dc595728d0d6@bmrb.wisc.edu> Date: Tue, 12 Mar 2019 10:36:45 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="twDYrDhvANBFAkGpNQlcdr7nkQlnUKhIi" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --twDYrDhvANBFAkGpNQlcdr7nkQlnUKhIi Content-Type: multipart/mixed; boundary="HzV1mhN3XQn3yAp8RVybNhATtdj2IAi0j"; protected-headers="v1" From: Jon Wedell To: pgsql-bugs@lists.postgresql.org Cc: Dimitri Maziuk Message-ID: <7ccaa770-ef82-42bf-dd56-dc595728d0d6@bmrb.wisc.edu> Subject: Bug involving plus sign before newline in text field being duplicated or stripped --HzV1mhN3XQn3yAp8RVybNhATtdj2IAi0j Content-Type: multipart/mixed; boundary="------------4B972DE47C52027CCEC107BE" Content-Language: en-US This is a multi-part message in MIME format. --------------4B972DE47C52027CCEC107BE Content-Type: multipart/alternative; boundary="------------941FCAA0DC41C6C3C92AD8D7" --------------941FCAA0DC41C6C3C92AD8D7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, This report contains either one or two distinct bugs, if they are two they appear related. First I noticed than when using the python pyscopg2-binary library, a plus sign immediately proceeding a newline at the end of a value was being stripped. When investigating further, I noticed that when directly using the psql command line interface, when inserting a text value ending with a plus sign and then a newline, the plus sign is duplicated. This behavior exists on the following three versions I have tested: PostgreSQL 11.2 (Ubuntu 11.2-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit and PostgreSQL 10.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23), 64-bit and PostgreSQL 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0, 64-bit I've attached very small example SQL and python files that reproduce the bug(s). The SQL file demonstrates the duplication bug - run it first. The python file demonstrates the stripping bug - run it after the table is created. Here is an example of the duplication bug (ran on a fresh 11.2 installation from the postgresql repo on Ubuntu 18.04, no configuration changes or start up options): wedell@manowar:~$ psql -U postgres psql (11.2 (Ubuntu 11.2-1.pgdg18.04+1)) Type "help" for help. postgres=3D# create table test (inchi text); CREATE TABLE postgres=3D# insert into test values ('test+ postgres'# '); INSERT 0 1 postgres=3D# select * from test; =C2=A0inchi ------- =C2=A0test++ =C2=A0 (1 row) As you can see, only one plus sign was inserted, but two are returned. (The expected return value was 'test+\n' but the actual value was 'test++\n'.) For reference, the second line as entered was insert into test values ('test+ '); The second bug is that pyscopg2-binary is stripping a plus sign at the end of the value out. The following example was ran immediately after the SQL above: wedell@manowar:~$ python Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) Type "copyright", "credits" or "license" for more information. IPython 5.5.0 -- An enhanced Interactive Python. ?=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -> Introduction and ove= rview of IPython's features. %quickref -> Quick reference. help=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -> Python's own help system. object?=C2=A0=C2=A0 -> Details about 'object', use 'object??' for extra d= etails. In [1]: import psycopg2 In [2]: conn =3D psycopg2.connect(user=3D'postgres') In [3]: cur =3D conn.cursor() In [4]: cur.execute('select * from test'); In [5]: print cur.fetchall() [('test+\n',)] Based on the psql response above, the expected value was 'test++\n' but the actual value was 'test+\n'. It is true that the original insert had one plus sign, but if psql is to be believed the value in the database now has two. This was how I originally noticed the problem; in a table I had a value which psql reports having just one plus sign, but psycopg2 strips it and returns a value with none. I'm happy to provide any other information necessary. Best Regards, Jon Wedell --------------941FCAA0DC41C6C3C92AD8D7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Hello,

This report contains either one or two distinct bugs, if they are two they appear related.

First I noticed than when using the python pyscopg2-binary library, a plus sign immediately proceeding a newline at the end of a value was being stripped.

When investigating further, I noticed that when directly using the psql command line interface, when inserting a text value ending with a plus sign and then a newline, the plus sign is duplicated.

This behavior exists on the following three versions I have tested:


PostgreSQL 11.2 (Ubuntu 11.2-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit

and

PostgreSQL 10.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23), 64-bit

and

PostgreSQL 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0, 64-bit


I've attached very small example SQL and python files that reproduce the bug(s). The SQL file demonstrates the duplication bug - run it first. The python file demonstrates the stripping bug - run it after the table is created.


Here is an example of the duplication bug (ran on a fresh 11.2 installation from the postgresql repo on Ubuntu 18.04, no configuration changes or start up options):

wedell@manowar:~$ psql -U postgres
psql (11.2 (Ubuntu 11.2-1.pgdg18.04+1))
Type "help" for help.

postgres=3D# create table test (inchi text);
CREATE TABLE
postgres=3D# insert into test values ('test+
postgres'# ');
INSERT 0 1
postgres=3D# select * from test;
=C2=A0inchi
-------
=C2=A0test++
=C2=A0
(1 row)


As you can see, only one plus sign was inserted, but two are returned. (The expected return value was 'test+\n' but the actual value was 'test++\n'.)


For reference, the second line as entered was

insert into test values ('test+
');


The second bug is that pyscopg2-binary is stripping a plus sign at the end of the value out. The following example was ran immediately after the SQL above:

wedell@manowar:~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -> Introductio= n and overview of IPython's features.
%quickref -> Quick reference.
help=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -> Python's own help system.<= br> object?=C2=A0=C2=A0 -> Details about 'object', use 'object??' fo= r extra details.

In [1]: import psycopg2
In [2]: conn =3D psycopg2.connect(user=3D'postgres')
In [3]: cur =3D conn.cursor()
In [4]: cur.execute('select * from test');
In [5]: print cur.fetchall()
[('test+\n',)]

Based on the psql response above, the expected value was 'test++\n' but the actual value was 'test+\n'.

It is true that the original insert had one plus sign, but if psql is to be believed the value in the database now has two. This was how I originally noticed the problem; in a table I had a value which psql reports having just one plus sign, but psycopg2 strips it and returns a value with none.


I'm happy to provide any other information necessary.


Best Regards,

Jon Wedell


--------------941FCAA0DC41C6C3C92AD8D7-- --------------4B972DE47C52027CCEC107BE Content-Type: text/plain; charset=UTF-8; name="bug.psql" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="bug.psql" ZHJvcCB0YWJsZSBpZiBleGlzdHMgdGVzdDsKY3JlYXRlIHRhYmxlIHRlc3QgKGluY2hpIHRl eHQpOwppbnNlcnQgaW50byB0ZXN0IHZhbHVlcyAoJ3Rlc3QrCicpOwpzZWxlY3QgKiBmcm9t IHRlc3Q7 --------------4B972DE47C52027CCEC107BE Content-Type: text/x-python; name="bug.py" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="bug.py" #!/usr/bin/env python2 from __future__ import print_function import psycopg2 conn =3D psycopg2.connect(user=3D'postgres') cur =3D conn.cursor() cur.execute('select * from test') print(cur.fetchall()) --------------4B972DE47C52027CCEC107BE-- --HzV1mhN3XQn3yAp8RVybNhATtdj2IAi0j-- --twDYrDhvANBFAkGpNQlcdr7nkQlnUKhIi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEFyCMpuxnR3vAfWGTLqbdram4MMEFAlyH0g0ACgkQLqbdram4 MMHROQgAutME+cQ5dcr8BezfFH8fioUP5/mpLOFcXpkxn6I1+joVrzyD25S1WM5B 9cxIRBCovnPKnuHjF8pwjZc58/bb936UzO29806mnzuhU9CAJZThQ4MEpCEr+WAM cQ06/CZ8rP3mdNNO45NUvEaE/W6sOkFJTfz3Lo2Hq6vRvHaU2E5oV4ZOSBup8biC Xna7xCtYc2a6BdbKfyuyzZTpEtN/Fy7a3g+oodGkbuYoi1I3dK5OumFylicPUI6o qdLEzXR/apeRZTeuJW/zpPeSx5WHH6hf1AUNEqsyACunPNQ3hbDMdZ3NLxrpGBwC ygtYR4/cYy6DFvedlEpqhNjQEa3//A== =f6va -----END PGP SIGNATURE----- --twDYrDhvANBFAkGpNQlcdr7nkQlnUKhIi--