Re: libpq parameter parsing problem

"David G. Johnston" <[email protected]> Tue, 14 Jan 2020 18:52:07 -0700
Newsgroups gmane.comp.db.postgresql.bugs
Message-ID <CAKFQuwaDd-azJDV_BQJj8R8Xxj6k35tehqwD0n7huTjgj+1Aqw@mail.gmail.com>
--000000000000e41495059c23f5db
Content-Type: text/plain; charset="UTF-8"

On Mon, Jan 13, 2020 at 11:32 PM Jobin Augustine <[email protected]> wrote:

> Hi Michael,
>
> On Tue, Jan 14, 2020 at 11:33 AM Michael Paquier <[email protected]>
> wrote:
>
>> On Mon, Jan 13, 2020 at 08:07:06PM +0530, Jobin Augustine wrote:
>> > Sorry for the late reply. Attaching a patch.
>>
>> >     <para>
>> > -    Percent-encoding may be used to include symbols with special
>> meaning in any
>> > -    of the <acronym>URI</acronym> parts, e.g. replace
>> <literal>=</literal> with
>> > -    <literal>%3D</literal>.
>> > -
>> > +    Connection <acronym>URI</acronym> need to be encoded with
>> > +    <ulink url="https://en.wikipedia.org/wiki/Percent-encoding">Percent-encoding</ulink>
>>
>> > +    if it includes symbols with special meaning in any of its parts.
>> > +    For example:
>> > +<programlisting>
>> > +postgresql://postgres@localhost
>> :5432/postgres?options=-c%20synchronous_commit%3Doff%20-c%20geqo%3Doff
>> > +</programlisting>
>> > +    where all <literal>=</literal> are replaced with
>> <literal>%3D</literal> and
>> > +    space character with <literal>%20</literal>
>> >     </para>
>>
>> The reference to wikipedia is nice to have.  A small nit from me is
>> that I would group the last sentence with the "For example", to give:
>> "Here is an example where all = are replaced.."
>>
> Yes, agree, readability is better with that modification.
> Attaching a modified patch.
>
>> The first sentence sounds good to me.
>>
>>
Should start out: "The Connection URI needs to be encoded with (confirm
OK-ness of wikipedia direct link in docs) Percent-encoding..." (mainly
"need => needs", the "the" reads better to me though)

I would probably choose to move the example for the options parameters to
the "Parameter Key Words" options section:

...represent a literal backslash.</p>

<p>When specifying options as part of a percent-encoded Connection URI the
structural space(s) and equal sign(s) "=" need to be encoded as %20 and %3D
respectively (in addition to any value-specific encoding needs) while the
escaping back-slash "\" does not.  For example:
<programlisting>postgresql:///mydb?options=-c%20synchronous_commit%3Doff%20-c%20geqo%3Doff</programlisting>

<p>For a detailed...

If you'd like an example for the first section maybe something like having
a space in your database name:

postgresql://user@localhost:5432/my%20database

Also, regardless of where it is placed having both the username and
database both be named "postgres" in an example just adds unnecessary
mental effort to understanding the example.  One that none of the existing
examples do.  Name your user "user" and database "mydb" unless, as with the
desire to include a space, there is a meaningful reason not to.

Also, in my modified example (for options) above since everything is
optional omitting everything except the database and parameters removes
noise (though keeping them may increase comfort).

David J.

--000000000000e41495059c23f5db
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:arial,helvetica,sans-serif"><span style=3D"font-family:Arial,Helve=
tica,sans-serif">On Mon, Jan 13, 2020 at 11:32 PM Jobin Augustine &lt;<a hr=
ef=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:</span><br>=
</div></div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padd=
ing-left:1ex"><div dir=3D"ltr"><div>Hi=C2=A0Michael,</div><br><div class=3D=
"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Jan 14, 2020 at=
 11:33 AM Michael Paquier &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt; wrote:<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex">On Mon, Jan 13, 2020 at 08:07:06PM +0530, =
Jobin Augustine wrote:<br>
&gt; Sorry for the late reply. Attaching a patch.<br>
<br>
&gt;=C2=A0 =C2=A0 =C2=A0&lt;para&gt;<br>
&gt; -=C2=A0 =C2=A0 Percent-encoding may be used to include symbols with sp=
ecial meaning in any<br>
&gt; -=C2=A0 =C2=A0 of the &lt;acronym&gt;URI&lt;/acronym&gt; parts, e.g. r=
eplace &lt;literal&gt;=3D&lt;/literal&gt; with<br>
&gt; -=C2=A0 =C2=A0 &lt;literal&gt;%3D&lt;/literal&gt;.<br>
&gt; -<br>
&gt; +=C2=A0 =C2=A0 Connection &lt;acronym&gt;URI&lt;/acronym&gt; need to b=
e encoded with <br>
&gt; +=C2=A0 =C2=A0 &lt;ulink url=3D&quot;<a href=3D"https://en.wikipedia.o=
rg/wiki/Percent-encoding" rel=3D"noreferrer" target=3D"_blank">https://en.w=
ikipedia.org/wiki/Percent-encoding</a>&quot;&gt;Percent-encoding&lt;/ulink&=
gt; <br>
&gt; +=C2=A0 =C2=A0 if it includes symbols with special meaning in any of i=
ts parts. <br>
&gt; +=C2=A0 =C2=A0 For example:<br>
&gt; +&lt;programlisting&gt;<br>
&gt; +postgresql://postgres@localhost:5432/postgres?options=3D-c%20synchron=
ous_commit%3Doff%20-c%20geqo%3Doff<br>
&gt; +&lt;/programlisting&gt;<br>
&gt; +=C2=A0 =C2=A0 where all &lt;literal&gt;=3D&lt;/literal&gt; are replac=
ed with &lt;literal&gt;%3D&lt;/literal&gt; and <br>
&gt; +=C2=A0 =C2=A0 space character with &lt;literal&gt;%20&lt;/literal&gt;=
<br>
&gt;=C2=A0 =C2=A0 =C2=A0&lt;/para&gt;<br>
<br>
The reference to wikipedia is nice to have.=C2=A0 A small nit from me is<br=
>
that I would group the last sentence with the &quot;For example&quot;, to g=
ive:<br>
&quot;Here is an example where all =3D are replaced..&quot;<br></blockquote=
><div>Yes, agree, readability is better with that modification.</div><div>A=
ttaching a modified patch.</div><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef=
t:1ex">
The first sentence sounds good to me.<br><br></blockquote></div></div></blo=
ckquote><div><br></div><div class=3D"gmail_default" style=3D"font-family:ar=
ial,helvetica,sans-serif">Should start out: &quot;The Connection URI needs =
to be encoded with (confirm OK-ness of wikipedia direct link in docs) Perce=
nt-encoding...&quot; (mainly &quot;need =3D&gt; needs&quot;, the &quot;the&=
quot; reads better to me though)</div><div class=3D"gmail_default" style=3D=
"font-family:arial,helvetica,sans-serif"><br></div><div class=3D"gmail_defa=
ult" style=3D"font-family:arial,helvetica,sans-serif">I would probably choo=
se to move the example for the options parameters to the &quot;Parameter Ke=
y Words&quot; options section:</div><div class=3D"gmail_default" style=3D"f=
ont-family:arial,helvetica,sans-serif"><br></div><div class=3D"gmail_defaul=
t" style=3D"font-family:arial,helvetica,sans-serif">...represent a literal =
backslash.&lt;/p&gt;</div><div class=3D"gmail_default" style=3D"font-family=
:arial,helvetica,sans-serif"><br></div><div class=3D"gmail_default" style=
=3D"font-family:arial,helvetica,sans-serif">&lt;p&gt;When specifying option=
s as part of a percent-encoded Connection URI the structural space(s) and e=
qual sign(s) &quot;=3D&quot; need to be encoded as %20 and %3D respectively=
 (in addition to any value-specific encoding needs) while the escaping back=
-slash &quot;\&quot; does not.=C2=A0 For example:</div><div class=3D"gmail_=
default" style=3D"font-family:arial,helvetica,sans-serif">&lt;programlistin=
g&gt;postgresql:///mydb?options=3D-c%20synchronous_commit%3Doff%20-c%20geqo=
%3Doff&lt;/programlisting&gt;</div><div class=3D"gmail_default" style=3D"fo=
nt-family:arial,helvetica,sans-serif"><br></div><div class=3D"gmail_default=
" style=3D"font-family:arial,helvetica,sans-serif">&lt;p&gt;For a detailed.=
..<br></div><div class=3D"gmail_default" style=3D"font-family:arial,helveti=
ca,sans-serif"><br></div><div class=3D"gmail_default" style=3D"font-family:=
arial,helvetica,sans-serif">If you&#39;d like an example for the first sect=
ion maybe something like having a space in your database name:</div><div cl=
ass=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif"><br>=
</div><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,san=
s-serif">postgresql://user@localhost:5432/my%20database</div><div class=3D"=
gmail_default" style=3D"font-family:arial,helvetica,sans-serif"><br></div><=
div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif=
">Also, regardless of where it is placed having both the username and datab=
ase both be named &quot;postgres&quot; in an example just adds unnecessary =
mental effort to understanding the example.=C2=A0 One that none of the exis=
ting examples do.=C2=A0 Name your user &quot;user&quot; and database &quot;=
mydb&quot; unless, as with the desire to include a space, there is a meanin=
gful reason not to.</div><div class=3D"gmail_default" style=3D"font-family:=
arial,helvetica,sans-serif"><br></div><div class=3D"gmail_default" style=3D=
"font-family:arial,helvetica,sans-serif">Also, in my modified example (for =
options) above since everything is optional omitting everything except the =
database and parameters removes noise (though keeping them may increase com=
fort).</div><div class=3D"gmail_default" style=3D"font-family:arial,helveti=
ca,sans-serif"><br></div><div class=3D"gmail_default" style=3D"font-family:=
arial,helvetica,sans-serif">David J.</div><div class=3D"gmail_default" styl=
e=3D"font-family:arial,helvetica,sans-serif"><br></div></div></div>

--000000000000e41495059c23f5db--