From 3bc1b6441b49f6bff6914bc068b98a09addd464d Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 3 Nov 2023 10:51:53 +0100 Subject: [PATCH] Properly quote items in sequences --- .../settings/docs-new-preamble-in.rst | 4 ++-- pdns/recursordist/settings/generate.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pdns/recursordist/settings/docs-new-preamble-in.rst b/pdns/recursordist/settings/docs-new-preamble-in.rst index e59cb5d1db..05e33f0dd1 100644 --- a/pdns/recursordist/settings/docs-new-preamble-in.rst +++ b/pdns/recursordist/settings/docs-new-preamble-in.rst @@ -43,7 +43,7 @@ An example :program:`Recursor` YAML configuration file looks like: loglevel: 6 Take care when listing IPv6 addresses, as characters used for these are special to YAML. -If in doubt, quote any string containing ``:``, ``[`` or ``]`` and use (online) tools to check your YAML syntax. +If in doubt, quote any string containing ``:``, ``!``, ``[`` or ``]`` and use (online) tools to check your YAML syntax. Specify an empty sequence using ``[]``. The main setting file is called ``recursor.yml`` and will be processed first. @@ -128,7 +128,7 @@ For example, ``alow-from`` takes a sequence of subnets: allow_from: - '2001:DB8::/32' - 128.66.0.0/16 - - !128.66.1.2 + - '!128.66.1.2' In this case the address ``128.66.1.2`` is excluded from the addresses allowed access. diff --git a/pdns/recursordist/settings/generate.py b/pdns/recursordist/settings/generate.py index 5129da3105..c06923e698 100644 --- a/pdns/recursordist/settings/generate.py +++ b/pdns/recursordist/settings/generate.py @@ -163,9 +163,21 @@ def get_default_newdoc_value(typ, val): return '(empty)' if typ == LType.String: return '``' + val + '``' - if val == '': - return '``[]``' - return '``[' + val + ']``' + parts = re.split('[ \t,]+', val) + if len(parts) > 0: + ret = '' + for part in parts: + if part == '': + continue + if ret != '': + ret += ', ' + if ':' in part or '!' in part: + ret += "'" + part + "'" + else: + ret += part + else: + ret = '' + return '``[' + ret + ']``' def get_rust_type(typ): """Determine which Rust type is used for a logical type""" -- 2.47.2