Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 6677785

Browse files
committed
Support (?i) in regexps
Related to #79.
1 parent 7c13a3a commit 6677785

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ make test
101101
* tarantool,
102102
* lulpeg,
103103
* >=tarantool/avro-schema-2.0-71-gfea0ead,
104-
* >=tarantool/shard-1.1-91-gfa88bf8 (optional),
105-
* lrexlib-pcre (optional).
104+
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) (optional),
105+
* lrexlib-pcre2 or lrexlib-pcre (optional).
106106
* For test (additionally to 'for use'):
107107
* python 2.7,
108108
* virtualenv,
109109
* luacheck,
110-
* >=tarantool/shard-1.1-92-gec1a27e.
110+
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0).
111111
* For building apidoc (additionally to 'for use'):
112112
* ldoc.
113113

graphql/accessor_general.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ local json = require('json')
99
local avro_schema = require('avro_schema')
1010
local utils = require('graphql.utils')
1111
local clock = require('clock')
12-
local rex = utils.optional_require('rex_pcre')
12+
local rex, is_pcre2 = utils.optional_require('rex_pcre2'), true
13+
if rex == nil then
14+
-- fallback to libpcre
15+
rex, is_pcre2 = utils.optional_require('rex_pcre'), false
16+
end
1317

1418
-- XXX: consider using [1] when it will be mature enough;
1519
-- look into [2] for the status.
@@ -777,8 +781,17 @@ local function match_using_re(obj, pcre)
777781
assert(rex ~= nil, 'we should not pass over :compile() ' ..
778782
'with a query contains PCRE matching when there are '..
779783
'no lrexlib-pcre (rex_pcre) module present')
784+
-- emulate behaviour of (?i) on libpcre (libpcre2 supports it)
785+
local cfg
786+
if not is_pcre2 then
787+
local cnt
788+
re, cnt = re:gsub('^%(%?i%)', '')
789+
if cnt > 0 then
790+
cfg = 'i'
791+
end
792+
end
780793
-- XXX: compile re once
781-
local re = rex.new(re)
794+
local re = rex.new(re, cfg)
782795
if not re:match(obj[field_name]) then
783796
return false
784797
end

test/local/space_pcre.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ QUERY
1212
VARIABLES
1313
---
1414
middle_name_re: ich$
15-
first_name_re: ^I
15+
first_name_re: (?i)^i
1616
...
1717

1818
RESULT

test/local/space_pcre.test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ local function run_queries(gql_wrapper)
8383

8484
utils.show_trace(function()
8585
local variables_1_1 = {
86-
first_name_re = '^I',
86+
first_name_re = '(?i)^i',
8787
middle_name_re = 'ich$',
8888
}
8989
local result = gql_query_1:execute(variables_1_1)

0 commit comments

Comments
 (0)