]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Fixing split_parts() in lib/pp_admintools/common.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2024 16:16:00 +0000 (17:16 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Nov 2024 16:16:00 +0000 (17:16 +0100)
lib/pp_admintools/common.py

index 6ca850cb48bbcc3c808a199d4fe45a962ea6d745..1bb69854261eb8be4f5d11e4653aa7d738da2c20 100644 (file)
@@ -34,7 +34,7 @@ except ImportError:
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.2.0'
+__version__ = '0.2.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -57,7 +57,7 @@ RE_SPLIT_SQ = re.compile(r"\\'")
 RE_SPLIT_SQ_CHUNK = re.compile(r"^'((?:\\'|[^'])*)'")
 RE_SPLIT_DQ = re.compile(r'\\"')
 RE_SPLIT_DQ_CHUNK = re.compile(r'^"((?:\\"|[^"])*)"')
-RE_SPLIT_UQ_CHUNK = re.compile(r'^((?:[^\s\'"]+|\\\'|\\")+)')
+RE_SPLIT_UQ_CHUNK = re.compile("^((?:[^\\s'\"]|\\'|\\\")+)")
 RE_SPLIT_WS_ALL = re.compile(r'^\s*$')
 RE_SPLIT_UNBALANCED = re.compile(r'^([\'"].*)\s*')
 
@@ -205,7 +205,7 @@ def split_parts(text, keep_quotes=False, raise_on_unbalanced=True):
         match = RE_SPLIT_DQ_CHUNK.search(txt)
         if match:
             chunk = match.group(1)
-            chunk = RE_SPLIT_DQ('"', chunk)
+            chunk = RE_SPLIT_DQ.sub('"', chunk)
             if keep_quotes:
                 chunk = '"' + chunk + '"'
             last_chunk += chunk
@@ -216,6 +216,8 @@ def split_parts(text, keep_quotes=False, raise_on_unbalanced=True):
         match = RE_SPLIT_UQ_CHUNK.search(txt)
         if match:
             last_chunk += match.group(1)
+            last_chunk = RE_SPLIT_SQ.sub("'", last_chunk)
+            last_chunk = RE_SPLIT_DQ.sub('"', last_chunk)
             txt = RE_SPLIT_UQ_CHUNK.sub('', txt)
             continue