Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rex_pcre dependency from core #167

Closed
subnetmarco opened this issue Apr 27, 2015 · 7 comments
Closed

Remove rex_pcre dependency from core #167

subnetmarco opened this issue Apr 27, 2015 · 7 comments
Milestone

Comments

@subnetmarco
Copy link
Member

Use Lua patterns instead.

@subnetmarco subnetmarco added this to the 0.2.1 milestone Apr 27, 2015
@thibaultcha
Copy link
Member

👍

@subnetmarco subnetmarco changed the title Remove rex_pcre dependency Remove rex_pcre dependency from core Apr 29, 2015
@thibaultcha
Copy link
Member

I am actually not sure if this is going to be possible. Places where we need a regex, checked if a test case with a working pattern is provided:

  • Validate a public_dns
  • Validate a uuid for entities in the Cassandra DAO
  • catching invalid target_url Catching invalid target urls #149 (needed soon)
  • Any future other plugin that will have to rely on regexes
  • Some places in the specs to extract strings of JSON
uuid
local x = "%x"
local pattern = "^"..table.concat({ x:rep(8), x:rep(4), x:rep(4), x:rep(4), x:rep(12) }, '%-').."$"

local guid = "3F2504E0-4F89-41D3-9A0C-0305E82C3301"
assert(guid:match(pattern))
guid = "fba88588-ffd0-4769-c782-7c537c92078d"
assert(guid:match(pattern))
guid = "fba88588-ffd0-4769-c782-7c537c92078dblah"
assert(not guid:match(pattern))
guid = "blahfba88588-ffd0-4769-c782-7c537c92078d"
assert(not guid:match(pattern))
guid = "3F2504E0-4F89-41D3-9A0C0305E82C3301"
assert(not guid:match(pattern))
guid = "304E0-4F89-41D3-9A0C0305E8^3301"
assert(not guid:match(pattern))
guid = "fba88588-féd0-4769-c782-7c537c92078d"
assert(not guid:match(pattern))
guid = "fba88588-(§è!)-4769-c782-7c537c92078d"
assert(not guid:match(pattern))
guid = "3F2504E0-4F89-41D3-9A0§-03(5E82C3301"
assert(not guid:match(pattern))
guid = "3F2504E0-4F89-41D3-9A0C0305é82C3301"
assert(not guid:match(pattern))
guid = "hello3F2504E0-4F89-41D3-9A0C0305é82C3301world"
assert(not guid:match(pattern))
guid = "abcd"
assert(not guid:match(pattern))
guid = ""
assert(not guid:match(pattern))
public_dns
local function is_valid_public_dns(str)
  -- check the format
  local pattern1 = "([A-Za-z0-9%-]*)%.*([A-Za-z0-9%-]*)%.([A-Za-z0-9][A-Za-z0-9]+)$"
  -- check all characters are alphanumeric
  local pattern2 = "^[%w%.%-]*$"
  -- both checks need to be true to be a valid public_dns
  return str:match(pattern1) and str:match(pattern2)
end

assert(is_valid_public_dns("mockbin.com"))
assert(is_valid_public_dns("foo-bar.mockbin.com"))
assert(is_valid_public_dns("mockbin.com"))
assert(is_valid_public_dns("mockbin.ninja"))
assert(is_valid_public_dns("api.mockbin.com"))
assert(not is_valid_public_dns("apiè!!.mockbin.com"))
assert(not is_valid_public_dns(""))
assert(not is_valid_public_dns("mockbincom"))
assert(not is_valid_public_dns( "mockbincom!!"))
assert(not is_valid_public_dns("mockbin.com!!"))
assert(not is_valid_public_dns("mockbin.com."))
specs

In the specs I was able to use a simple pattern to extract JSON string from a log line:

local json_str = line:match("(%{.*%})")

@subnetmarco
Copy link
Member Author

If if it's not feasible to remove it from everywhere, we shouldn't force it. Just reduce regex usage to the places where it's absolutely necessary would be okay.

@thibaultcha
Copy link
Member

It might be possible, we might also use a slightly more enhanced way of using the patterns (like a library: http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html)

@thibaultcha
Copy link
Member

Just updated the issue with a working version of a public_dns check. Please do test it with other values you could think of.

@thibaultcha
Copy link
Member

Updated for the specs part too

@thibaultcha
Copy link
Member

Merged #167 which does some improvements and use patterns in most places instead of regexes. PCRE is not removed and the regex field is still available in schema definitions.

hutchic added a commit that referenced this issue Nov 21, 2019
)

* chore(ci) [skip travis] move nightly releases to Jenkins

* [skip travis]

* [skip travis] split plugin tests out and login to docker when building the docker test image

* [skip travis] try a different way of defining the KONG_VERSION env

* [skip travis] skip the problematic builds

* [skip travis] move the daily deploys out of travis.yml

* [skip travis] wip debugging a sporadically failing test

* fix(tests) adjust how we run the report mock server for a more reliable test

* chore(ci) debug the environment variables available in jenkins [skip travis]

* chore(ci) set the repository os name environment variable [skip travis]

* test(reports) adjust how we check if the report server can run

* chore(ci) adjust the jenkins setup [skip travis]

* chore(wip) remove the integration tests to focus on getting the nightly releases to work

* fix(ci) adjust how set set the bintray credentials [skip travis]

* wip -- debugging daily releases to bintray [skip travis]

* chore(ci) run only the xenial release [skip travis]

* chore(ci) re-enable tests and other distribution releases

* chore(ci) add the CI cron trigger

chore(dependency) bump the kong-build-tools dependency (#168)

chore(dependencies) adjust kong-build-tools dependency pin (#169)

* chore(dependency) bump the kong-build-tools dependency

* chore(ci) unpin the jenkins build from the kong-build-tools branch

chore(nightly) build nightly arm release (#171)

chore(ci) adjust cache settings for xenail nightly builds (#173)
hutchic added a commit that referenced this issue Nov 21, 2019
)

* chore(ci) [skip travis] move nightly releases to Jenkins

* [skip travis]

* [skip travis] split plugin tests out and login to docker when building the docker test image

* [skip travis] try a different way of defining the KONG_VERSION env

* [skip travis] skip the problematic builds

* [skip travis] move the daily deploys out of travis.yml

* [skip travis] wip debugging a sporadically failing test

* fix(tests) adjust how we run the report mock server for a more reliable test

* chore(ci) debug the environment variables available in jenkins [skip travis]

* chore(ci) set the repository os name environment variable [skip travis]

* test(reports) adjust how we check if the report server can run

* chore(ci) adjust the jenkins setup [skip travis]

* chore(wip) remove the integration tests to focus on getting the nightly releases to work

* fix(ci) adjust how set set the bintray credentials [skip travis]

* wip -- debugging daily releases to bintray [skip travis]

* chore(ci) run only the xenial release [skip travis]

* chore(ci) re-enable tests and other distribution releases

* chore(ci) add the CI cron trigger

chore(dependency) bump the kong-build-tools dependency (#168)

chore(dependencies) adjust kong-build-tools dependency pin (#169)

* chore(dependency) bump the kong-build-tools dependency

* chore(ci) unpin the jenkins build from the kong-build-tools branch

chore(nightly) build nightly arm release (#171)

chore(ci) adjust cache settings for xenail nightly builds (#173)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants