]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: Fix whitespace handling
authorSebastian Wagner <sewagner@redhat.com>
Wed, 2 Jun 2021 10:41:36 +0000 (12:41 +0200)
committerSage Weil <sage@newdream.net>
Thu, 17 Jun 2021 20:18:06 +0000 (16:18 -0400)
keep whitespace in lines starting with %url

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
src/pybind/mgr/nfs/export_utils.py

index e4842393245eed2027b82e7872de8be0c786d121..e9b5c7936323a6a58181d3a160a9d609ddfdb951 100644 (file)
@@ -10,23 +10,24 @@ class GaneshaConfParser:
         self.pos = 0
         self.text = ""
         for line in raw_config.split("\n"):
-            self.text += line
+            line = line.lstrip()
+
             if line.startswith("%"):
+                self.text += line.replace('"', "")
                 self.text += "\n"
-
-    def remove_whitespaces_quotes(self):
-        if self.text.startswith("%url"):
-            self.text = self.text.replace('"', "")
-        else:
-            self.text = "".join(self.text.split())
+            else:
+                self.text += "".join(line.split())
 
     def stream(self):
         return self.text[self.pos:]
 
+    def last_context(self) -> str:
+        return f'"...{self.text[max(0, self.pos - 30):self.pos]}<here>{self.stream()[:30]}"'
+
     def parse_block_name(self):
         idx = self.stream().find('{')
         if idx == -1:
-            raise Exception("Cannot find block name")
+            raise Exception(f"Cannot find block name at {self.last_context()}")
         block_name = self.stream()[:idx]
         self.pos += idx+1
         return block_name
@@ -104,7 +105,6 @@ class GaneshaConfParser:
                 raise Exception("Infinite loop while parsing block content")
 
     def parse(self):
-        self.remove_whitespaces_quotes()
         blocks = []
         while self.stream():
             blocks.append(self.parse_block_or_section())