From bca8bb9a74a042e70a72d7f41403dda68b2a6306 Mon Sep 17 00:00:00 2001 From: Peter Silva Date: Wed, 18 Sep 2024 16:42:04 -0400 Subject: [PATCH] if topic is malformed, just do not set anything --- sarracenia/__init__.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/sarracenia/__init__.py b/sarracenia/__init__.py index 148d1268f..652bc99e7 100755 --- a/sarracenia/__init__.py +++ b/sarracenia/__init__.py @@ -526,25 +526,17 @@ def deriveTopics(msg,o,inbound_topic,separator='.'): """ msg_topic = inbound_topic.split(separator) # topic validation... deal with DMS topic scheme. https://github.com/MetPX/sarracenia/issues/1017 - if 'topicCopy' in o and o['topicCopy']: - topicOverride=True - else: - topicOverride=False - if 'relPath' in msg: - path_topic = o['topicPrefix'] + os.path.dirname(msg['relPath']).split('/') - - if msg_topic != path_topic: - topicOverride=True - - # set subtopic if possible. - if msg_topic[0:len(o['topicPrefix'])] == o['topicPrefix']: - msg['subtopic'] = msg_topic[len(o['topicPrefix']):] - else: - topicOverride=True + topicOverride = 'topicCopy' in o and o['topicCopy'] if topicOverride: msg['topic'] = inbound_topic msg['_deleteOnPost'] |= set( ['topic'] ) + else: + # if the topic isn't as expected by Sarracenia, leave subtopic unset. + # set subtopic if possible. + if msg_topic[0:len(o['topicPrefix'])] == o['topicPrefix']: + msg['subtopic'] = msg_topic[len(o['topicPrefix']):] + msg['_deleteOnPost'] |= set(['subtopic']) def dumps(msg) -> str: