Re: encode/decode support for base64url
Chao Li <li.evan.chao@gmail.com>
From: Chao Li <li.evan.chao@gmail.com>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>, Florents Tselai <florents.tselai@gmail.com>, "David E. Wheeler" <david@justatheory.com>, Aleksander Alekseev <aleksander@tigerdata.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>, Cary Huang <cary.huang@highgo.ca>, Przemysław Sztoch <przemyslaw@sztoch.pl>
Date: 2025-09-19T03:50:00Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add support for base64url encoding and decoding
- e1d917182c19 19 (unreleased) landed
I reviewed and tested this patch. Overall looks good to me. Actually, I think this patched fixed a bug of current implementation of base64 encoding by moving the logic of handling newline into “if (pos<0)”.
Just a few small comments:
> On Sep 19, 2025, at 03:19, Daniel Gustafsson <daniel@yesql.se> wrote:
>
> <v9-0001-Add-support-for-base64url-encoding-and-decoding.patch>
1.
```
+ * Helper for decoding base64 or base64url. When url is passed as true the
+ * input will be encoded using base64url. len bytes in src is encoded into
+ * dst.
+ */
```
It’s not common to use two white-spaces after “.”, usually we need only one.
2.
```
+ /* handle remainder */
if (pos != 2)
```
The comment is understandable, but slightly vague: remainder of what?
Maybe rephrase to “handle remaining bytes in buf”.
3.
```
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unexpected \"=\" while decoding base64 sequence")));
+ errmsg("unexpected \"=\" while decoding %s sequence", url ? "base64url" : "base64")));
```
This is a normal usage that injects sub-strings based on condition. However, PG doesn’t like that, see here: https://www.postgresql.org/docs/devel/nls-programmer.html#NLS-GUIDELINES
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/