diff --git a/CHANGES b/CHANGES index 2fae864..dadabb5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,22 @@ +1.2.9-56 | 2024-12-09 14:00:22 +0100 + + * Fix formatting of nodes with no non-error children (Benjamin Bannier, Corelight) + + When formatting a `Node`'s child we allowed omitting passing in of the + child to format. In that case the user would pass a `None` child and we + would attempt to default to formatting the next non-error child. The + helper we used to get that child could still return `None` (in case + there were only error children remaining, or on incorrect use of the + function when the node had no children), but we never handled that case; + instead we would have surfaced an `AttributeError` like + + ``` + AttributeError: 'NoneType' object has no attribute 'prev_error_siblings' + ``` + + With this path we explicitly skip any child formatting if we found no + child to be formatted. + 1.2.9-54 | 2024-12-09 14:00:03 +0100 * Bump pre-commit hooks (Benjamin Bannier, Corelight) diff --git a/VERSION b/VERSION index c902f4d..d9a78fd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.9-54 +1.2.9-56 diff --git a/zeekscript/__init__.py b/zeekscript/__init__.py index 82677ee..13aeca3 100644 --- a/zeekscript/__init__.py +++ b/zeekscript/__init__.py @@ -1,6 +1,6 @@ """Wrapper around more low-level tests.""" -__version__ = "1.2.9-54" +__version__ = "1.2.9-56" __all__ = [ "Formatter", "Script", diff --git a/zeekscript/formatter.py b/zeekscript/formatter.py index 2fa2dc2..01c04ab 100644 --- a/zeekscript/formatter.py +++ b/zeekscript/formatter.py @@ -149,6 +149,8 @@ def _format_child_impl(self, node, indent, hints=None): def _format_child(self, child=None, indent=False, hints=None): if child is None: child = self._next_child() + if child is None: + return # XXX Pretty subtle that we handle the child's surrounding context here, # in the parent. Might have to refactor in the future.