mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Refactor logic to check for ASCII-only characters in string
The same logic was present for collation commands, SASLprep and pgcrypto, so this removes some code. Author: Michael Paquier Reviewed-by: Stephen Frost, Heikki Linnakangas Discussion: https://postgr.es/m/X9womIn6rne6Gud2@paquier.xyz
This commit is contained in:
@ -32,6 +32,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "catalog/pg_type.h"
|
||||
#include "common/string.h"
|
||||
#include "funcapi.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
@ -92,19 +93,6 @@ convert_to_utf8(text *src)
|
||||
return convert_charset(src, GetDatabaseEncoding(), PG_UTF8);
|
||||
}
|
||||
|
||||
static bool
|
||||
string_is_ascii(const char *str)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
if (IS_HIGHBIT_SET(*p))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
clear_and_pfree(text *p)
|
||||
{
|
||||
@ -814,7 +802,7 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
|
||||
|
||||
v = TextDatumGetCString(key_datums[i]);
|
||||
|
||||
if (!string_is_ascii(v))
|
||||
if (!pg_is_ascii(v))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("header key must not contain non-ASCII characters")));
|
||||
@ -836,7 +824,7 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
|
||||
|
||||
v = TextDatumGetCString(val_datums[i]);
|
||||
|
||||
if (!string_is_ascii(v))
|
||||
if (!pg_is_ascii(v))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("header value must not contain non-ASCII characters")));
|
||||
|
Reference in New Issue
Block a user