Skip to content

Commit 427f7e0

Browse files
committed
feat: switch from crossplane to ngxparse for NGINX parsing
ngxparse is a maintained fork with improved braced variable tokenization. Closes #89
1 parent 8adf4e4 commit 427f7e0

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
crossplane>=0.5.8
1+
ngxparse>=0.5.16
22
cached-property>=1.2.0
33
argparse>=1.4.0
44
Jinja2>=2.8

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
raise RuntimeError("Cannot find version information")
1717

1818
install_requires = [
19-
"crossplane>=0.5.8",
19+
"ngxparse>=0.5.16",
2020
'cached-property>=1.2.0;python_version<"3.8"',
2121
'argparse>=1.4.0;python_version<"3.2"',
2222
"Jinja2>=2.8",

tests/parser/test_raw_parser_minimal.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,38 @@ def test_inline_comments_filtered_but_standalone_kept():
9696
assert "Standalone" in texts
9797
# Inline comment should not appear as a standalone comment node
9898
assert not any(t and "Inline" in t for t in texts)
99+
100+
101+
def test_braced_variable_args_split():
102+
"""
103+
Regression test for braced variable tokenization.
104+
105+
Prior to ngxparse 0.5.16, crossplane incorrectly tokenized
106+
'map ${var1}${var2} $result' as having a single arg '${var1}${var2} $result'
107+
instead of two separate args. This test ensures the fix works correctly.
108+
"""
109+
config = """
110+
http {
111+
map ${detect_bot}${geo_list} $intermed {
112+
default 0;
113+
}
114+
}
115+
"""
116+
nodes = RawParser().parse(config)
117+
118+
# Find the map block
119+
def find_blocks(ns, name):
120+
for x in ns:
121+
if x.get("name") == name and x.get("kind") == "block":
122+
yield x
123+
if x.get("kind") == "block":
124+
yield from find_blocks(x.get("children", []), name)
125+
126+
map_blocks = list(find_blocks(nodes, "map"))
127+
assert len(map_blocks) == 1
128+
map_block = map_blocks[0]
129+
130+
# Args should be split correctly: ['${detect_bot}${geo_list}', '$intermed']
131+
assert len(map_block.get("args", [])) == 2
132+
assert map_block["args"][0] == "${detect_bot}${geo_list}"
133+
assert map_block["args"][1] == "$intermed"

0 commit comments

Comments
 (0)