diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-08-26 10:41:31 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-08-26 13:53:09 -0400 |
commit | e86fdb0ab224eaa73d907ab16a2dd0e0058699e0 (patch) | |
tree | 19bed12afd338f89ab119dbf830114e60ca75f11 /src/bin/psql/variables.c | |
parent | 910725b49ddf5c827658717f458fb14d0044f251 (diff) | |
download | postgresql-e86fdb0ab224eaa73d907ab16a2dd0e0058699e0.tar.gz postgresql-e86fdb0ab224eaa73d907ab16a2dd0e0058699e0.zip |
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.
Diffstat (limited to 'src/bin/psql/variables.c')
-rw-r--r-- | src/bin/psql/variables.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c index 38252893377..a43c786bf02 100644 --- a/src/bin/psql/variables.c +++ b/src/bin/psql/variables.c @@ -6,11 +6,41 @@ * 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; |