yandex / gixy

Nginx configuration static analyzer
Other
8.27k stars 394 forks source link

[regexp] Add internal opition settings support #78

Open dzavalkinolx opened 6 years ago

dzavalkinolx commented 6 years ago

I have the following code in my nginx config:

# new frontend base routes
location /public/ {
    alias /usr/share/nginx/html;

    location ~ "^/public/[0-9a-fA-F.]{32}/forPhp/(?<path>(?U).*)$" {
        try_files /forPhp/$path =404;
    }
}

This code produces the following error while validating it with gixy:

[regexp]    CRITICAL    Failed to parse regex: ^/public/[0-9a-fA-F.]{32}/forPhp/(?<path>(?U).*)$ (unexpected end of pattern)
Traceback (most recent call last):
  File "/usr/local/bin/gixy", line 11, in <module>
    load_entry_point('gixy==0.1.9', 'console_scripts', 'gixy')()
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/cli/main.py", line 169, in main
    yoda.audit(path, fdata, is_stdin=False)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 27, in audit
    self._audit_recursive(self.root.children)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 53, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 53, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 53, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 53, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 48, in _audit_recursive
    self._update_variables(directive)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/manager.py", line 63, in _update_variables
    for var in directive.variables:
  File "/usr/local/lib/python2.7/site-packages/cached_property-1.4.0-py2.7.egg/cached_property.py", line 32, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/directives/block.py", line 119, in variables
    for name, group in regexp.groups.items():
  File "/usr/local/lib/python2.7/site-packages/cached_property-1.4.0-py2.7.egg/cached_property.py", line 32, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/regexp.py", line 1004, in groups
    for name, parsed in extract_groups(self.parsed).items():
  File "/usr/local/lib/python2.7/site-packages/gixy-0.1.9-py2.7.egg/gixy/core/regexp.py", line 1029, in parsed
    raise e
gixy.core.sre_parse.sre_constants.error: unexpected end of pattern

Not sure, maybe a duplicate of #57

buglloc commented 6 years ago

For now Gixy doesn't support PCRE internal opition settings I'll work on it.