diff --git a/dzonegit.py b/dzonegit.py index ffcce6a..22fc388 100644 --- a/dzonegit.py +++ b/dzonegit.py @@ -112,15 +112,15 @@ def get_altered_files(against, diff_filter=None): return (Path(p) for p in r.stdout.rstrip("\0").split("\0")) -def get_zone_origin(zonedata, maxlines=10): +def get_zone_origin(zonedata): """ - Parse $ORIGIN directive in first maxlines lines of zone file. + Parse $ORIGIN directive before the SOA record. Return zone name without the trailing dot. """ - for i, line in enumerate(zonedata.splitlines()): - if i >= maxlines: + for line in zonedata.splitlines(): + if re.match(r"^[^\s;]+\s+([0-9]+\s+)?(IN\s+)?SOA\s+", line, re.I): break - m = re.match(r"^\$ORIGIN\s+([^ ]+)\.\s*(;.*)?$", line) + m = re.match(r"^\$ORIGIN\s+([^ ]+)\.\s*(;.*)?$", line, re.I) if m: return m.group(1).lower() diff --git a/tests/test_dzonegit.py b/tests/test_dzonegit.py index da4dcf0..9a8ff44 100644 --- a/tests/test_dzonegit.py +++ b/tests/test_dzonegit.py @@ -88,16 +88,10 @@ $ORIGIN example.com. testzone = """ @ 60 IN SOA ns hostmaster 1 60 60 60 60 60 IN NS ns +$ORIGIN example.com. ns.example.com. 60 IN A 192.0.2.1 """ assert get_zone_origin(testzone) is None - testzone = """ -@ 60 IN SOA ns hostmaster 1 60 60 60 60 - 60 IN NS ns -ns.example.com. 60 IN A 192.0.2.1 -$ORIGIN sub.example.com. -""" - assert get_zone_origin(testzone, 4) is None def test_get_zone_name():