mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
Support non-ASCII letters in psql variable names.
As in the backend, the implementation actually accepts any non-ASCII character, but we only document that you can use letters.
This commit is contained in:
@ -6,10 +6,40 @@
|
||||
* src/bin/psql/variables.c
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "variables.h"
|
||||
|
||||
|
||||
/*
|
||||
* Check whether a variable's name is allowed.
|
||||
*
|
||||
* We allow any non-ASCII character, as well as ASCII letters, digits, and
|
||||
* underscore. Keep this in sync with the definition of variable_char in
|
||||
* psqlscan.l.
|
||||
*/
|
||||
static bool
|
||||
valid_variable_name(const char *name)
|
||||
{
|
||||
const unsigned char *ptr = (const unsigned char *) name;
|
||||
|
||||
/* Mustn't be zero-length */
|
||||
if (*ptr == '\0')
|
||||
return false;
|
||||
|
||||
while (*ptr)
|
||||
{
|
||||
if (IS_HIGHBIT_SET(*ptr) ||
|
||||
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
|
||||
"_0123456789", *ptr) != NULL)
|
||||
ptr++;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* A "variable space" is represented by an otherwise-unused struct _variable
|
||||
* that serves as list header.
|
||||
@ -158,7 +188,7 @@ SetVariable(VariableSpace space, const char *name, const char *value)
|
||||
if (!space)
|
||||
return false;
|
||||
|
||||
if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name))
|
||||
if (!valid_variable_name(name))
|
||||
return false;
|
||||
|
||||
if (!value)
|
||||
@ -202,7 +232,7 @@ SetVariableAssignHook(VariableSpace space, const char *name, VariableAssignHook
|
||||
if (!space)
|
||||
return false;
|
||||
|
||||
if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name))
|
||||
if (!valid_variable_name(name))
|
||||
return false;
|
||||
|
||||
for (previous = space, current = space->next;
|
||||
|
Reference in New Issue
Block a user