fix field parse regex

This commit is contained in:
gmega 2024-02-05 17:23:35 -03:00
parent 0a34c82360
commit 6e0e3a0485
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
2 changed files with 20 additions and 2 deletions

View File

@ -14,9 +14,9 @@ _LOG_LINE = re.compile(
r'count=(?P<count>\d+)$'
)
_TOPICS = re.compile(r'((\w+=("[\w\s]+"|\S+) )+)?\w+=("[\w\s]+"|\S+)$')
_TOPICS = re.compile(r'((\w+=("[^"]+"|\S+) )+)?\w+=("[^"]+"|\S+)$')
_TOPICS_KV = re.compile(r'(?P<key>\w+)=(?P<value>"[\w\s]+"|\S+)')
_TOPICS_KV = re.compile(r'(?P<key>\w+)=(?P<value>"[^"]+"|\S+)')
class LogLevel(Enum):

View File

@ -50,3 +50,21 @@ def test_should_parse_chronicles_fields():
'type': 'WantBlock',
'items': '1',
}
def test_should_parse_topics_with_non_alphanumeric_characters():
source = ChroniclesRawSource(
StringLogSource(
lines='WRN 2024-02-02 20:38:47.316+00:00 a message topics="codex pendingblocks" address="cid: zDx*QP4zx9" '
'count=10641'
)
).__iter__()
line = next(source)
assert line.message == "a message"
assert line.count == 10641
assert line.fields == {
'topics': '"codex pendingblocks"',
'address': '"cid: zDx*QP4zx9"',
}