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

Support (?i) in regexps #119

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ make test
* tarantool,
* lulpeg,
* >=tarantool/avro-schema-2.0-71-gfea0ead,
* >=tarantool/shard-1.1-91-gfa88bf8 (optional),
* lrexlib-pcre (optional).
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) (optional),
* lrexlib-pcre2 or lrexlib-pcre (optional).
* For test (additionally to 'for use'):
* python 2.7,
* virtualenv,
* luacheck,
* >=tarantool/shard-1.1-92-gec1a27e.
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0).
* For building apidoc (additionally to 'for use'):
* ldoc.

Expand Down
17 changes: 15 additions & 2 deletions graphql/accessor_general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ local json = require('json')
local avro_schema = require('avro_schema')
local utils = require('graphql.utils')
local clock = require('clock')
local rex = utils.optional_require('rex_pcre')
local rex, is_pcre2 = utils.optional_require('rex_pcre2'), true
if rex == nil then
-- fallback to libpcre
rex, is_pcre2 = utils.optional_require('rex_pcre'), false
end

-- XXX: consider using [1] when it will be mature enough;
-- look into [2] for the status.
Expand Down Expand Up @@ -777,8 +781,17 @@ local function match_using_re(obj, pcre)
assert(rex ~= nil, 'we should not pass over :compile() ' ..
'with a query contains PCRE matching when there are '..
'no lrexlib-pcre (rex_pcre) module present')
-- emulate behaviour of (?i) on libpcre (libpcre2 supports it)
local cfg
if not is_pcre2 then
local cnt
re, cnt = re:gsub('^%(%?i%)', '')
if cnt > 0 then
cfg = 'i'
end
end
-- XXX: compile re once
local re = rex.new(re)
local re = rex.new(re, cfg)
if not re:match(obj[field_name]) then
return false
end
Expand Down
2 changes: 1 addition & 1 deletion test/local/space_pcre.result
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QUERY
VARIABLES
---
middle_name_re: ich$
first_name_re: ^I
first_name_re: (?i)^i
...

RESULT
Expand Down
2 changes: 1 addition & 1 deletion test/local/space_pcre.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ local function run_queries(gql_wrapper)

utils.show_trace(function()
local variables_1_1 = {
first_name_re = '^I',
first_name_re = '(?i)^i',
middle_name_re = 'ich$',
}
local result = gql_query_1:execute(variables_1_1)
Expand Down