From e59b53a58825a4705fbea563c1001a4e020a495b Mon Sep 17 00:00:00 2001 From: Michal Sadowski Date: Fri, 23 Feb 2018 09:56:44 +0100 Subject: [PATCH] Add map container --- .gitignore | 1 + CHANGELOG | 4 ++++ nginx.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/.gitignore b/.gitignore index e796898..de1b720 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist build *.pyc *.egg-info +.idea diff --git a/CHANGELOG b/CHANGELOG index f6c50da..d8cdc74 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased +### Fixed +- Fixed bug with map crashing loading of nginx.conf. + ## [1.2.0] - 2017-09-06 ### Fixed - Fixed several bugs involving parsing of messy files and brace locations (thanks @lelik9!) diff --git a/nginx.py b/nginx.py index 1bcc6f5..866aea3 100755 --- a/nginx.py +++ b/nginx.py @@ -345,6 +345,15 @@ def __init__(self, value, *args): self.name = 'geo' +class Map(Container): + """Container for map configuration.""" + + def __init__(self, value, *args): + """Initialize.""" + super(Map, self).__init__(value, *args) + self.name = 'map' + + class Key(object): """Represents a simple key/value object found in an nginx config.""" @@ -438,6 +447,13 @@ def loads(data, conf=True): index += m.end() continue + m = re.compile(r'^\s*map\s*(.*?\S+)\s*{', re.S).search(data[index:]) + if m: + g = Map(m.group(1)) + lopen.insert(0, g) + index += m.end() + continue + m = re.compile(r'^(\s*)#\s*(.*?)\n', re.S).search(data[index:]) if m: c = Comment(m.group(2), inline='\n' not in m.group(1))