TimberBot – commitdiff

You can use Git to clone the repository via the web URL. Download snapshot (zip)
Make command argument parsing accept more different quotation characters
authorJulian Fietkau <git@fietkau.software>
Wed, 9 Oct 2024 16:36:54 +0000 (18:36 +0200)
committerJulian Fietkau <git@fietkau.software>
Wed, 9 Oct 2024 16:36:54 +0000 (18:36 +0200)
parser.py

index f08c3b217b888940aab2f2ef379527398801fc84..e0f9fe9029ef2f98ae3ca512dbd28ee926206783 100644 (file)
--- a/parser.py
+++ b/parser.py
@@ -85,24 +85,36 @@ class Parser:
                 break
         if not is_command:
             return result
+        quotation_pairs = ['""', '\'\'', '“”', '””', '‘’', '„“', '„”', '‚’', '’’', '‚‘', '»«', '«»', '›‹', '‹›', '「」', '『』', '〈〉', '《》']
+        quotation_matches = {}
+        for pair in quotation_pairs:
+            if pair[0] not in quotation_matches:
+                quotation_matches[pair[0]] = []
+            quotation_matches[pair[0]].append(pair[1])
         current = ''
         index = 0
-        protected = False
         while index < len(message):
             char = message[index]
-            if char == ' ' and not protected:
+            if char == ' ':
                 if len(current) > 0:
                     if current[-1] == ',':
                         current = current[:-1]
                     result.append(current)
                     current = ''
-            elif char in ['"', '\''] and not protected:
-                protected = char
-            elif char == protected:
-                protected = False
-            else:
-                current = current + char
-            index = index + 1
+                    char = ''
+            elif char in quotation_matches and len(current) == 0:
+                end_index = index + 1
+                while end_index < len(message):
+                    if message[end_index] in quotation_matches[char] and (end_index == len(message) - 1 or message[end_index + 1] == ' '):
+                        result.append(message[index+1:end_index])
+                        index = end_index + 1
+                        break
+                    end_index += 1
+                if end_index < len(message):
+                    index = end_index + 1
+                    char = ''
+            current = current + char
+            index += 1
         if len(current) > 0:
             if current[-1] == ',':
                 current = current[:-1]