aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/arrayfuncs.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-07-06 08:16:24 +0900
committerMichael Paquier <michael@paquier.xyz>2023-07-06 08:16:24 +0900
commitae6d06f09684d8f8a7084514c9b35a274babca61 (patch)
treed1d4572bb1224f16f36b80a8c64ede605a698530 /src/backend/utils/adt/arrayfuncs.c
parent4f4d73466d71976b58f29121bab9d9fef6f3436e (diff)
downloadpostgresql-ae6d06f09684d8f8a7084514c9b35a274babca61.tar.gz
postgresql-ae6d06f09684d8f8a7084514c9b35a274babca61.zip
Handle \v as a whitespace character in parsers
This commit comes as a continuation of the discussion that has led to d522b05, as \v was handled inconsistently when parsing array values or anything going through the parsers, and changing a parser behavior in stable branches is a scary thing to do. The parsing of array values now uses the more central scanner_isspace() and array_isspace() is removed. As pointing out by Peter Eisentraut, fix a confusing reference to horizontal space in the parsers with the term "horiz_space". \f was included in this set since 3cfdd8f from 2000, but it is not horizontal. "horiz_space" is renamed to "non_newline_space", to refer to all whitespace characters except newlines. The changes impact the parsers for the backend, psql, seg, cube, ecpg and replication commands. Note that JSON should not escape \v, as per RFC 7159, so these are not touched. Reviewed-by: Peter Eisentraut, Tom Lane Discussion: https://postgr.es/m/ZJKcjNwWHHvw9ksQ@paquier.xyz
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r--src/backend/utils/adt/arrayfuncs.c35
1 files changed, 7 insertions, 28 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 9000f83a836..4359dbd83df 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -24,6 +24,7 @@
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "optimizer/optimizer.h"
+#include "parser/scansup.h"
#include "port/pg_bitutils.h"
#include "utils/array.h"
#include "utils/arrayaccess.h"
@@ -89,7 +90,6 @@ typedef struct ArrayIteratorData
int current_item; /* the item # we're at in the array */
} ArrayIteratorData;
-static bool array_isspace(char ch);
static int ArrayCount(const char *str, int *dim, char typdelim,
Node *escontext);
static bool ReadArrayStr(char *arrayStr, const char *origStr,
@@ -254,7 +254,7 @@ array_in(PG_FUNCTION_ARGS)
* Note: we currently allow whitespace between, but not within,
* dimension items.
*/
- while (array_isspace(*p))
+ while (scanner_isspace(*p))
p++;
if (*p != '[')
break; /* no more dimension items */
@@ -338,7 +338,7 @@ array_in(PG_FUNCTION_ARGS)
errdetail("Missing \"%s\" after array dimensions.",
ASSGN)));
p += strlen(ASSGN);
- while (array_isspace(*p))
+ while (scanner_isspace(*p))
p++;
/*
@@ -435,27 +435,6 @@ array_in(PG_FUNCTION_ARGS)
}
/*
- * array_isspace() --- a non-locale-dependent isspace()
- *
- * We used to use isspace() for parsing array values, but that has
- * undesirable results: an array value might be silently interpreted
- * differently depending on the locale setting. Now we just hard-wire
- * the traditional ASCII definition of isspace().
- */
-static bool
-array_isspace(char ch)
-{
- if (ch == ' ' ||
- ch == '\t' ||
- ch == '\n' ||
- ch == '\r' ||
- ch == '\v' ||
- ch == '\f')
- return true;
- return false;
-}
-
-/*
* ArrayCount
* Determines the dimensions for an array string.
*
@@ -654,7 +633,7 @@ ArrayCount(const char *str, int *dim, char typdelim, Node *escontext)
itemdone = true;
nelems[nest_level - 1]++;
}
- else if (!array_isspace(*ptr))
+ else if (!scanner_isspace(*ptr))
{
/*
* Other non-space characters must be after a
@@ -684,7 +663,7 @@ ArrayCount(const char *str, int *dim, char typdelim, Node *escontext)
/* only whitespace is allowed after the closing brace */
while (*ptr)
{
- if (!array_isspace(*ptr++))
+ if (!scanner_isspace(*ptr++))
ereturn(escontext, -1,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", str),
@@ -884,7 +863,7 @@ ReadArrayStr(char *arrayStr,
indx[ndim - 1]++;
srcptr++;
}
- else if (array_isspace(*srcptr))
+ else if (scanner_isspace(*srcptr))
{
/*
* If leading space, drop it immediately. Else, copy
@@ -1176,7 +1155,7 @@ array_out(PG_FUNCTION_ARGS)
overall_length += 1;
}
else if (ch == '{' || ch == '}' || ch == typdelim ||
- array_isspace(ch))
+ scanner_isspace(ch))
needquote = true;
}
}