Merge pull request #4653 from landychan/lchan/bug-fix-3611

Nginx Resource: Add parsing support for wildcard, dot prefix, and regex
This commit is contained in:
Miah Johnson 2019-10-31 14:20:08 -07:00 committed by GitHub
commit 1b93755410
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -18,7 +18,7 @@ class NginxParser < Parslet::Parser
end
rule(:standard_identifier) do
(match("[a-zA-Z]") >> match('\S').repeat).as(:identifier) >> space >> space.repeat
(match("[a-zA-Z~*.]") >> match('\S').repeat).as(:identifier) >> space >> space.repeat
end
rule(:quoted_identifier) do

View file

@ -85,6 +85,19 @@ describe NginxParser do
it "parses quoted identifiers for assignments" do
_(parsestr(%{"~^\/opcache-api" 1;})).must_equal "[{:assignment=>{:identifier=>\"~^/opcache-api\"@1, :args=>[{:value=>\"1\"@17}]}}]"
end
it "parses regex identifiers for assignments" do
_(parsestr(%{~^\/opcache-api 1;})).must_equal "[{:assignment=>{:identifier=>\"~^/opcache-api\"@0, :args=>[{:value=>\"1\"@15}]}}]"
end
it "parses wildcard identifiers for assignments" do
_(parsestr(%{*.example.org qa;})).must_equal "[{:assignment=>{:identifier=>\"*.example.org\"@0, :args=>[{:value=>\"qa\"@14}]}}]"
end
it "parses dot-prefixed identifiers for assignments" do
_(parsestr(%{.example.com test;})).must_equal "[{:assignment=>{:identifier=>\".example.com\"@0, :args=>[{:value=>\"test\"@13}]}}]"
end
end
describe NginxTransform do