[Libguestfs] [PATCH] builder: handle empty lines in indexes before first section (RHBZ#1201526)

Pino Toscano ptoscano at redhat.com
Fri Mar 13 14:02:58 UTC 2015


Properly skip empty lines before the first section, otherwise they will
trigger a syntax error in parsing.

Add a simple test for it, so it doesn't regress.
---
 builder/index-parse.y                   | 8 ++++----
 builder/test-virt-index-validate-good-3 | 4 ++++
 builder/test-virt-index-validate.sh     | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)
 create mode 100644 builder/test-virt-index-validate-good-3

diff --git a/builder/index-parse.y b/builder/index-parse.y
index 8ea2d73..82ea9d2 100644
--- a/builder/index-parse.y
+++ b/builder/index-parse.y
@@ -104,10 +104,10 @@ index:
         { context->parsed_index = $2; }
 
 sections:
-      section emptylines
-        { $$ = $1; }
-    | section EMPTY_LINE emptylines sections
-        { $$ = $1; $$->next = $4; }
+      emptylines section emptylines
+        { $$ = $2; }
+    | emptylines section EMPTY_LINE emptylines sections
+        { $$ = $2; $$->next = $5; }
     | emptylines
         { $$ = NULL; }
 
diff --git a/builder/test-virt-index-validate-good-3 b/builder/test-virt-index-validate-good-3
new file mode 100644
index 0000000..f10adf0
--- /dev/null
+++ b/builder/test-virt-index-validate-good-3
@@ -0,0 +1,4 @@
+# Empty lines before the first section
+
+[foo]
+key=value
diff --git a/builder/test-virt-index-validate.sh b/builder/test-virt-index-validate.sh
index c66929d..b00a086 100755
--- a/builder/test-virt-index-validate.sh
+++ b/builder/test-virt-index-validate.sh
@@ -22,3 +22,4 @@ set -e
 ! $VG virt-index-validate test-virt-index-validate-bad-1
 $VG virt-index-validate test-virt-index-validate-good-1
 $VG virt-index-validate test-virt-index-validate-good-2
+$VG virt-index-validate test-virt-index-validate-good-3
-- 
2.1.0




More information about the Libguestfs mailing list