From 4e88571216d809085478dc35b05995ad52f40659 Mon Sep 17 00:00:00 2001 From: gmega Date: Mon, 5 Feb 2024 19:12:16 -0300 Subject: [PATCH] reorder regex so escaped strings match first --- .../log/sources/parse/chronicles_raw_source.py | 4 ++-- .../parse/tests/test_chronicles_raw_source.py | 18 ++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/logtools/log/sources/parse/chronicles_raw_source.py b/logtools/log/sources/parse/chronicles_raw_source.py index 21918d6..1ecc54a 100644 --- a/logtools/log/sources/parse/chronicles_raw_source.py +++ b/logtools/log/sources/parse/chronicles_raw_source.py @@ -14,9 +14,9 @@ _LOG_LINE = re.compile( r'count=(?P\d+)$' ) -_TOPICS = re.compile(r'((\w+=("[^"]+"|\S+) )+)?\w+=("([^"\\]|\\")+"|\S+)$') +_TOPICS = re.compile(r'((\w+=("[^"]+"|\S+) )+)?\w+=("(\\"|[^"])+"|\S+)$') -_TOPICS_KV = re.compile(r'(?P\w+)=(?P"(?:[^"\\]|\\")+"|\S+)') +_TOPICS_KV = re.compile(r'(?P\w+)=(?P"(?:\\"|[^"])+"|\S+)') class LogLevel(Enum): diff --git a/logtools/log/sources/parse/tests/test_chronicles_raw_source.py b/logtools/log/sources/parse/tests/test_chronicles_raw_source.py index 7addb4f..e44099d 100644 --- a/logtools/log/sources/parse/tests/test_chronicles_raw_source.py +++ b/logtools/log/sources/parse/tests/test_chronicles_raw_source.py @@ -86,3 +86,21 @@ def test_should_parse_topics_with_escaped_quotes_in_values(): 'topics': '"codex pendingblocks"', 'address': '"cid: \\"zDx*QP4zx9\\""', } + + +def test_should_parse_topics_with_escaped_quotes_and_backlashes_in_value(): + source = ChroniclesRawSource( + StringLogSource( + lines='TRC 2024-02-02 20:37:18.316+00:00 Starting codex node topics="codex node" ' + 'config="some \\"quoted\\" string with \'more\' escape chars" count=7' + ) + ).__iter__() + + line = next(source) + + assert line.message == "Starting codex node" + assert line.count == 7 + assert line.fields == { + 'topics': '"codex node"', + 'config': '"some \\"quoted\\" string with \'more\' escape chars"', + } diff --git a/pyproject.toml b/pyproject.toml index 94e92eb..add7dd6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "logtools" -version = "1.1.2" +version = "1.1.3" description = "" authors = ["gmega "] readme = "README.md"