Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,14 @@ def loads(data, conf=True):
index += m.end()
continue

s1 = r'("[^"]+"|\'[^\']+\'|[^\s;]+)'
s2 = r'("[^"]*"|\'[^\']*\'|[^\s;]*)'
s3 = r'(\s*[^;]*?)'
key = r'^\s*{}\s*{}{};'.format(s1, s2, s3)
m = re.compile(key, re.S).search(data[index:])
double = r'\s*"[^"]*"'
single = r'\s*\'[^\']*\''
normal = r'\s*[^;\s]*'
s1 = r'{}|{}|{}'.format(double, single, normal)
s = r'^\s*({})\s*((?:{})+);'.format(s1, s1)
m = re.compile(s, re.S).search(data[index:])
if m:
k = Key(m.group(1), m.group(2) + m.group(3))
k = Key(m.group(1), m.group(2))
if lopen and isinstance(lopen[0], (Container, Server)):
lopen[0].add(k)
else:
Expand Down
13 changes: 13 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
}
"""

TESTBLOCK_CASE_9 = """
location test9 {
add_header X-XSS-Protection "1;mode-block";
}
"""

class TestPythonNginx(unittest.TestCase):
def test_basic_load(self):
Expand Down Expand Up @@ -259,6 +264,14 @@ def test_limit_expect(self):
self.assertEqual(first_key.name, "deny")
self.assertEqual(first_key.value, "all")

def test_semicolon_in_second_key_value(self):
inp_data = nginx.loads(TESTBLOCK_CASE_9)
self.assertEqual(len(inp_data.filter("Location")), 1)
location_children = inp_data.filter("Location")[0].children
self.assertEqual(len(location_children), 1)
self.assertEqual(location_children[0].name, "add_header")
self.assertEqual(location_children[0].value, 'X-XSS-Protection "1;mode-block"')


if __name__ == '__main__':
unittest.main()