Skip to content

Commit a2a5ce6

Browse files
committed
Improve "invalid byte sequence for encoding" message
It used to say ERROR: invalid byte sequence for encoding "UTF8": 0xdb24 Change this to ERROR: invalid byte sequence for encoding "UTF8": 0xdb 0x24 to make it clear that this is a byte sequence and not a code point. Also fix the adjacent "character has no equivalent" message that has the same issue.
1 parent 7cb99b2 commit a2a5ce6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/backend/utils/mb/wchar.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ void
15951595
report_invalid_encoding(int encoding, const char *mbstr, int len)
15961596
{
15971597
int l = pg_encoding_mblen(encoding, mbstr);
1598-
char buf[8 * 2 + 1];
1598+
char buf[8 * 5 + 1];
15991599
char *p = buf;
16001600
int j,
16011601
jlimit;
@@ -1604,11 +1604,15 @@ report_invalid_encoding(int encoding, const char *mbstr, int len)
16041604
jlimit = Min(jlimit, 8); /* prevent buffer overrun */
16051605

16061606
for (j = 0; j < jlimit; j++)
1607-
p += sprintf(p, "%02x", (unsigned char) mbstr[j]);
1607+
{
1608+
p += sprintf(p, "0x%02x", (unsigned char) mbstr[j]);
1609+
if (j < jlimit - 1)
1610+
p += sprintf(p, " ");
1611+
}
16081612

16091613
ereport(ERROR,
16101614
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
1611-
errmsg("invalid byte sequence for encoding \"%s\": 0x%s",
1615+
errmsg("invalid byte sequence for encoding \"%s\": %s",
16121616
pg_enc2name_tbl[encoding].name,
16131617
buf)));
16141618
}
@@ -1624,7 +1628,7 @@ report_untranslatable_char(int src_encoding, int dest_encoding,
16241628
const char *mbstr, int len)
16251629
{
16261630
int l = pg_encoding_mblen(src_encoding, mbstr);
1627-
char buf[8 * 2 + 1];
1631+
char buf[8 * 5 + 1];
16281632
char *p = buf;
16291633
int j,
16301634
jlimit;
@@ -1633,11 +1637,15 @@ report_untranslatable_char(int src_encoding, int dest_encoding,
16331637
jlimit = Min(jlimit, 8); /* prevent buffer overrun */
16341638

16351639
for (j = 0; j < jlimit; j++)
1636-
p += sprintf(p, "%02x", (unsigned char) mbstr[j]);
1640+
{
1641+
p += sprintf(p, "0x%02x", (unsigned char) mbstr[j]);
1642+
if (j < jlimit - 1)
1643+
p += sprintf(p, " ");
1644+
}
16371645

16381646
ereport(ERROR,
16391647
(errcode(ERRCODE_UNTRANSLATABLE_CHARACTER),
1640-
errmsg("character 0x%s of encoding \"%s\" has no equivalent in \"%s\"",
1648+
errmsg("character with byte sequence %s in encoding \"%s\" has no equivalent in encoding \"%s\"",
16411649
buf,
16421650
pg_enc2name_tbl[src_encoding].name,
16431651
pg_enc2name_tbl[dest_encoding].name)));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy