diff options
Diffstat (limited to 'src/pl/plperl/plperl_helpers.h')
-rw-r--r-- | src/pl/plperl/plperl_helpers.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/pl/plperl/plperl_helpers.h b/src/pl/plperl/plperl_helpers.h index 81c177b164b..ac0a97d7aa6 100644 --- a/src/pl/plperl/plperl_helpers.h +++ b/src/pl/plperl/plperl_helpers.h @@ -7,10 +7,21 @@ static inline char * utf_u2e(const char *utf8_str, size_t len) { - char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, GetDatabaseEncoding()); + int enc = GetDatabaseEncoding(); + + char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, enc); + + /* + * when we are a PG_UTF8 or SQL_ASCII database + * pg_do_encoding_conversion() will not do any conversion or + * verification. we need to do it manually instead. + */ + if (enc == PG_UTF8 || enc == PG_SQL_ASCII) + pg_verify_mbstr_len(PG_UTF8, utf8_str, len, false); if (ret == utf8_str) ret = pstrdup(ret); + return ret; } |