pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix bogus handling of XQuery regex option flags. 2+ messages / 1 participants [nested] [flat]
* pgsql: Fix bogus handling of XQuery regex option flags. @ 2019-09-17 19:40 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2019-09-17 19:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/d5b90cd648558a4fd714b1396176ddb028ec28fc Modified Files -------------- src/backend/utils/adt/jsonpath.c | 2 +- src/backend/utils/adt/jsonpath_exec.c | 26 +---------- src/backend/utils/adt/jsonpath_gram.y | 64 ++++++++++++++++++++++------ src/include/utils/jsonpath.h | 8 ++-- src/test/regress/expected/jsonb_jsonpath.out | 11 ++--- src/test/regress/expected/jsonpath.out | 20 ++++----- src/test/regress/sql/jsonb_jsonpath.sql | 8 ++-- 7 files changed, 76 insertions(+), 63 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Fix bogus handling of XQuery regex option flags. @ 2019-09-17 19:40 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2019-09-17 19:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/14888145420802a32ec018246e12f3b377c61c29 Modified Files -------------- src/backend/utils/adt/jsonpath.c | 2 +- src/backend/utils/adt/jsonpath_exec.c | 26 +---------- src/backend/utils/adt/jsonpath_gram.y | 64 ++++++++++++++++++++++------ src/include/utils/jsonpath.h | 8 ++-- src/test/regress/expected/jsonb_jsonpath.out | 11 ++--- src/test/regress/expected/jsonpath.out | 20 ++++----- src/test/regress/sql/jsonb_jsonpath.sql | 8 ++-- 7 files changed, 76 insertions(+), 63 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-09-17 19:40 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-09-17 19:40 pgsql: Fix bogus handling of XQuery regex option flags. Tom Lane <tgl@sss.pgh.pa.us> 2019-09-17 19:40 pgsql: Fix bogus handling of XQuery regex option flags. Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox