mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
Added wildcard and dot-prefixed identifier support. Combined regex identifier into standard identifier
Signed-off-by: Landy Chan <landychan92@gmail.com>
This commit is contained in:
parent
e60179b91f
commit
9e38bec396
2 changed files with 11 additions and 6 deletions
|
@ -18,19 +18,15 @@ 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
|
||||
str('"') >> (str('"').absent? >> any).repeat.as(:identifier) >> str('"') >> space.repeat
|
||||
end
|
||||
|
||||
rule(:regex_identifier) do
|
||||
(str("~") >> match('\S').repeat).as(:identifier) >> space >> space.repeat
|
||||
end
|
||||
|
||||
rule(:identifier) do
|
||||
standard_identifier | quoted_identifier | regex_identifier
|
||||
standard_identifier | quoted_identifier
|
||||
end
|
||||
|
||||
rule(:standard_value) do
|
||||
|
|
|
@ -89,6 +89,15 @@ describe NginxParser do
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue