aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/jsonpath.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-09-17 15:39:51 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-09-17 15:39:51 -0400
commitd5b90cd648558a4fd714b1396176ddb028ec28fc (patch)
tree6a7070e0ea594c1c7261f62675021028c0d3ec1e /src/include/utils/jsonpath.h
parenta25221f53c7960e00484c801f10d2e989b75a7f2 (diff)
downloadpostgresql-d5b90cd648558a4fd714b1396176ddb028ec28fc.tar.gz
postgresql-d5b90cd648558a4fd714b1396176ddb028ec28fc.zip
Fix bogus handling of XQuery regex option flags.
The SQL spec defers to XQuery to define what the option flags are for LIKE_REGEX patterns. XQuery says that: * 's' allows the dot character to match newlines, which by default it will not; * 'm' allows ^ and $ to match at newlines, not only at the start/end of the whole string. Thus, these are *not* inverses as they are for the similarly-named POSIX options, and neither one corresponds to the POSIX 'n' option. Fortunately, Spencer's library does expose these two behaviors as separately twiddlable flags, so we just have to fix the mapping from JSP flag bits to REG flag bits. I also chose to rename the symbol for 's' to DOTALL, to make it clearer that it's not the inverse of MLINE. Also, XQuery says that if the 'q' flag "is used together with the m, s, or x flag, that flag has no effect". I read this as saying that 'q' overrides the other flags; whoever wrote our code seems to have read it backwards. Lastly, while XQuery's 'x' flag is related to what Spencer's code does for REG_EXPANDED, it's not the same or a subset. It seems best to treat XQuery's 'x' as unimplemented for now. Maybe later we can expand our regex code to offer 'x'-style parsing as a separate option. While at it, refactor the jsonpath code so that (a) there's only one copy of the flag transformation logic not two, and (b) the processing of flags is independent of the order in which the flags are written. We need some documentation updates to go with this, but I'll tackle that separately. Back-patch to v12 where this code originated. Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com Reference: https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#flags
Diffstat (limited to 'src/include/utils/jsonpath.h')
-rw-r--r--src/include/utils/jsonpath.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/include/utils/jsonpath.h b/src/include/utils/jsonpath.h
index 40ad5fda928..8458346bd4c 100644
--- a/src/include/utils/jsonpath.h
+++ b/src/include/utils/jsonpath.h
@@ -88,9 +88,9 @@ typedef enum JsonPathItemType
/* XQuery regex mode flags for LIKE_REGEX predicate */
#define JSP_REGEX_ICASE 0x01 /* i flag, case insensitive */
-#define JSP_REGEX_SLINE 0x02 /* s flag, single-line mode */
-#define JSP_REGEX_MLINE 0x04 /* m flag, multi-line mode */
-#define JSP_REGEX_WSPACE 0x08 /* x flag, expanded syntax */
+#define JSP_REGEX_DOTALL 0x02 /* s flag, dot matches newline */
+#define JSP_REGEX_MLINE 0x04 /* m flag, ^/$ match at newlines */
+#define JSP_REGEX_WSPACE 0x08 /* x flag, ignore whitespace in pattern */
#define JSP_REGEX_QUOTE 0x10 /* q flag, no special characters */
/*
@@ -245,4 +245,6 @@ typedef struct JsonPathParseResult
extern JsonPathParseResult *parsejsonpath(const char *str, int len);
+extern int jspConvertRegexFlags(uint32 xflags);
+
#endif