Commit 2955c2be authored by Tom Lane's avatar Tom Lane

Re-allow custom GUC names that have more than two components.

Commit 3db826bd disallowed this case, but it turns out that some
people are depending on it.  Since the core grammar has allowed
it since 3dc37cd8, it seems like this code should fall in line.

Per bug #17045 from Robert Sosinski.

Discussion: https://postgr.es/m/17045-6a4a9f0d1513f72b@postgresql.org
parent 8e03eb92
...@@ -5368,13 +5368,14 @@ add_guc_variable(struct config_generic *var, int elevel) ...@@ -5368,13 +5368,14 @@ add_guc_variable(struct config_generic *var, int elevel)
/* /*
* Decide whether a proposed custom variable name is allowed. * Decide whether a proposed custom variable name is allowed.
* *
* It must be "identifier.identifier", where the rules for what is an * It must be two or more identifiers separated by dots, where the rules
* identifier agree with scan.l. * for what is an identifier agree with scan.l. (If you change this rule,
* adjust the errdetail in find_option().)
*/ */
static bool static bool
valid_custom_variable_name(const char *name) valid_custom_variable_name(const char *name)
{ {
int num_sep = 0; bool saw_sep = false;
bool name_start = true; bool name_start = true;
for (const char *p = name; *p; p++) for (const char *p = name; *p; p++)
...@@ -5383,7 +5384,7 @@ valid_custom_variable_name(const char *name) ...@@ -5383,7 +5384,7 @@ valid_custom_variable_name(const char *name)
{ {
if (name_start) if (name_start)
return false; /* empty name component */ return false; /* empty name component */
num_sep++; saw_sep = true;
name_start = true; name_start = true;
} }
else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
...@@ -5400,8 +5401,8 @@ valid_custom_variable_name(const char *name) ...@@ -5400,8 +5401,8 @@ valid_custom_variable_name(const char *name)
} }
if (name_start) if (name_start)
return false; /* empty name component */ return false; /* empty name component */
/* OK if we had exactly one separator */ /* OK if we found at least one separator */
return (num_sep == 1); return saw_sep;
} }
/* /*
...@@ -5516,7 +5517,7 @@ find_option(const char *name, bool create_placeholders, bool skip_errors, ...@@ -5516,7 +5517,7 @@ find_option(const char *name, bool create_placeholders, bool skip_errors,
(errcode(ERRCODE_INVALID_NAME), (errcode(ERRCODE_INVALID_NAME),
errmsg("invalid configuration parameter name \"%s\"", errmsg("invalid configuration parameter name \"%s\"",
name), name),
errdetail("Custom parameter names must be of the form \"identifier.identifier\"."))); errdetail("Custom parameter names must be two or more simple identifiers separated by dots.")));
return NULL; return NULL;
} }
} }
......
...@@ -515,6 +515,8 @@ SET no_such_variable TO 42; ...@@ -515,6 +515,8 @@ SET no_such_variable TO 42;
ERROR: unrecognized configuration parameter "no_such_variable" ERROR: unrecognized configuration parameter "no_such_variable"
-- Test "custom" GUCs created on the fly (which aren't really an -- Test "custom" GUCs created on the fly (which aren't really an
-- intended feature, but many people use them). -- intended feature, but many people use them).
SHOW custom.my_guc; -- error, not known yet
ERROR: unrecognized configuration parameter "custom.my_guc"
SET custom.my_guc = 42; SET custom.my_guc = 42;
SHOW custom.my_guc; SHOW custom.my_guc;
custom.my_guc custom.my_guc
...@@ -522,14 +524,28 @@ SHOW custom.my_guc; ...@@ -522,14 +524,28 @@ SHOW custom.my_guc;
42 42
(1 row) (1 row)
RESET custom.my_guc; -- this makes it go to empty, not become unknown again
SHOW custom.my_guc;
custom.my_guc
---------------
(1 row)
SET custom.my.qualified.guc = 'foo';
SHOW custom.my.qualified.guc;
custom.my.qualified.guc
-------------------------
foo
(1 row)
SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name
ERROR: invalid configuration parameter name "custom.bad-guc" ERROR: invalid configuration parameter name "custom.bad-guc"
DETAIL: Custom parameter names must be of the form "identifier.identifier". DETAIL: Custom parameter names must be two or more simple identifiers separated by dots.
SHOW custom."bad-guc"; SHOW custom."bad-guc";
ERROR: unrecognized configuration parameter "custom.bad-guc" ERROR: unrecognized configuration parameter "custom.bad-guc"
SET special."weird name" = 'foo'; -- could be allowed, but we choose not to SET special."weird name" = 'foo'; -- could be allowed, but we choose not to
ERROR: invalid configuration parameter name "special.weird name" ERROR: invalid configuration parameter name "special.weird name"
DETAIL: Custom parameter names must be of the form "identifier.identifier". DETAIL: Custom parameter names must be two or more simple identifiers separated by dots.
SHOW special."weird name"; SHOW special."weird name";
ERROR: unrecognized configuration parameter "special.weird name" ERROR: unrecognized configuration parameter "special.weird name"
-- --
......
...@@ -151,8 +151,13 @@ SET no_such_variable TO 42; ...@@ -151,8 +151,13 @@ SET no_such_variable TO 42;
-- Test "custom" GUCs created on the fly (which aren't really an -- Test "custom" GUCs created on the fly (which aren't really an
-- intended feature, but many people use them). -- intended feature, but many people use them).
SHOW custom.my_guc; -- error, not known yet
SET custom.my_guc = 42; SET custom.my_guc = 42;
SHOW custom.my_guc; SHOW custom.my_guc;
RESET custom.my_guc; -- this makes it go to empty, not become unknown again
SHOW custom.my_guc;
SET custom.my.qualified.guc = 'foo';
SHOW custom.my.qualified.guc;
SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name
SHOW custom."bad-guc"; SHOW custom."bad-guc";
SET special."weird name" = 'foo'; -- could be allowed, but we choose not to SET special."weird name" = 'foo'; -- could be allowed, but we choose not to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment