Fix the parsing code in the grub2 handler so that it no longer gets hopelessly confus...
authorColin Watson <cjwatson@debian.org>
Mon, 17 Sep 2012 17:48:40 +0000 (18:48 +0100)
committerColin Watson <cjwatson@debian.org>
Mon, 17 Sep 2012 17:48:40 +0000 (18:48 +0100)
debian/changelog
linux-boot-probes/mounted/common/40grub2

index 925707a..7025706 100644 (file)
@@ -4,6 +4,11 @@ os-prober (1.56) UNRELEASED; urgency=low
   * Add support for probing Fedora's location for the GRUB 2 configuration
     file (closes: #674560).
 
+  [ Colin Watson ]
+  * Fix the parsing code in the grub2 handler so that it no longer gets
+    hopelessly confused by multiple single-quoted strings on the same line,
+    as produced by GRUB 2.00.
+
  -- Colin Watson <cjwatson@debian.org>  Mon, 17 Sep 2012 16:15:56 +0100
 
 os-prober (1.55) unstable; urgency=low
index d8ea294..885614e 100755 (executable)
@@ -44,13 +44,17 @@ parse_grub_menu () {
                                entry_result
                                shift 1
                                # The double-quoted string is the title.
-                               title="$(echo "$@" | sed -n 's/[^"]*"\(.*\)".*/\1/p' | sed 's/://g')"
+                               # Make sure to look at the text of the line
+                               # before 'set' mangled it.
+                               title="$(echo "$line" | sed -n 's/[^"]*"\(.*\)".*/\1/p' | sed 's/://g')"
                                if [ -z "$title" ]; then
-                                       # ... or single-quoted?  The
-                                       # unescaping here is odd because the
-                                       # 'set' above has already eaten
-                                       # backslash-escapes.
-                                       title="$(echo "$@" | sed -n "s/[^']*'\(.*\)'.*/\1/p" | sed "s/'''/'/; s/://g")"
+                                       # ... or single-quoted?  Be careful
+                                       # to handle constructions like
+                                       # 'foo'\''bar' (which expands to
+                                       # foo'bar, as in shell), and to
+                                       # handle multiple single-quoted
+                                       # strings on the same line.
+                                       title="$(echo "$line" | sed -n "s/[^']*'\(\([^']\|'\\\\''\)*\)'.*/\1/p" | sed "s/'\\\\''/'/; s/://g")"
                                fi
                                if [ -z "$title" ]; then
                                        ignore_item=1