All of lore.kernel.org
 help / color / mirror / Atom feed
* [wic][PATCH] wic: fix parsing of 'bitbake -e' output
@ 2016-12-21 14:19 Ed Bartosh
  2016-12-21 14:31 ` Maciej Borzęcki
  0 siblings, 1 reply; 4+ messages in thread
From: Ed Bartosh @ 2016-12-21 14:19 UTC (permalink / raw)
  To: openembedded-core

Current parsing code can wrongly interpret arbitrary lines
that are of 'key=value' format as legitimate bitbake variables.

Implemented more strict parsing of key=value pairs using
regular expressions.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 scripts/lib/wic/utils/oe/misc.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
index fe188c9..1dbbe92 100644
--- a/scripts/lib/wic/utils/oe/misc.py
+++ b/scripts/lib/wic/utils/oe/misc.py
@@ -27,6 +27,7 @@
 """Miscellaneous functions."""
 
 import os
+import re
 from collections import defaultdict
 from distutils import spawn
 
@@ -155,14 +156,11 @@ class BitbakeVars(defaultdict):
         """
         if "=" not in line:
             return
-        try:
-            key, val = line.split("=")
-        except ValueError:
+        match = re.match("^(\w+)=(.+)", line)
+        if not match:
             return
-        key = key.strip()
-        val = val.strip()
-        if key.replace('_', '').isalnum():
-            self[image][key] = val.strip('"')
+        key, val = match.groups()
+        self[image][key] = val.strip('"')
 
     def get_var(self, var, image=None):
         """
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [wic][PATCH] wic: fix parsing of 'bitbake -e' output
  2016-12-21 14:19 [wic][PATCH] wic: fix parsing of 'bitbake -e' output Ed Bartosh
@ 2016-12-21 14:31 ` Maciej Borzęcki
  2016-12-21 15:05   ` [wic][PATCH v2] " Ed Bartosh
  0 siblings, 1 reply; 4+ messages in thread
From: Maciej Borzęcki @ 2016-12-21 14:31 UTC (permalink / raw)
  To: Ed Bartosh; +Cc: Patches and discussions about the oe-core layer

On Wed, Dec 21, 2016 at 3:19 PM, Ed Bartosh <ed.bartosh@linux.intel.com> wrote:
> Current parsing code can wrongly interpret arbitrary lines
> that are of 'key=value' format as legitimate bitbake variables.
>
> Implemented more strict parsing of key=value pairs using
> regular expressions.
>
> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
> ---
>  scripts/lib/wic/utils/oe/misc.py | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
> index fe188c9..1dbbe92 100644
> --- a/scripts/lib/wic/utils/oe/misc.py
> +++ b/scripts/lib/wic/utils/oe/misc.py
> @@ -27,6 +27,7 @@
>  """Miscellaneous functions."""
>
>  import os
> +import re
>  from collections import defaultdict
>  from distutils import spawn
>
> @@ -155,14 +156,11 @@ class BitbakeVars(defaultdict):
>          """
>          if "=" not in line:
>              return
> -        try:
> -            key, val = line.split("=")
> -        except ValueError:
> +        match = re.match("^(\w+)=(.+)", line)

match = re.match(r"^(\w+)=(.+)", line)

I don't remember if regexps are cached when compiled in re.match(), but
perhaps it would be better to `re.compile(r"^(\w+)=(.+)")` in
BitbakeVars.__init__() and just use a cached object here?

> +        if not match:
>              return
> -        key = key.strip()
> -        val = val.strip()
> -        if key.replace('_', '').isalnum():
> -            self[image][key] = val.strip('"')
> +        key, val = match.groups()
> +        self[image][key] = val.strip('"')
>
>      def get_var(self, var, image=None):
>          """
> --
> 2.1.4
>

-- 
Maciej Borzecki
RnDity


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [wic][PATCH v2] wic: fix parsing of 'bitbake -e' output
  2016-12-21 14:31 ` Maciej Borzęcki
@ 2016-12-21 15:05   ` Ed Bartosh
  2016-12-21 17:16     ` Maciej Borzęcki
  0 siblings, 1 reply; 4+ messages in thread
From: Ed Bartosh @ 2016-12-21 15:05 UTC (permalink / raw)
  To: openembedded-core

Current parsing code can wrongly interpret arbitrary lines
that are of 'key=value' format as legitimate bitbake variables.

Implemented more strict parsing of key=value pairs using
regular expressions.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 scripts/lib/wic/utils/oe/misc.py | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
index fe188c9..2a2fcc9 100644
--- a/scripts/lib/wic/utils/oe/misc.py
+++ b/scripts/lib/wic/utils/oe/misc.py
@@ -27,6 +27,7 @@
 """Miscellaneous functions."""
 
 import os
+import re
 from collections import defaultdict
 from distutils import spawn
 
@@ -148,21 +149,18 @@ class BitbakeVars(defaultdict):
         self.default_image = None
         self.vars_dir = None
 
-    def _parse_line(self, line, image):
+    def _parse_line(self, line, image, matcher=re.compile(r"^(\w+)=(.+)")):
         """
         Parse one line from bitbake -e output or from .env file.
         Put result key-value pair into the storage.
         """
         if "=" not in line:
             return
-        try:
-            key, val = line.split("=")
-        except ValueError:
+        match = matcher.match(line)
+        if not match:
             return
-        key = key.strip()
-        val = val.strip()
-        if key.replace('_', '').isalnum():
-            self[image][key] = val.strip('"')
+        key, val = match.groups()
+        self[image][key] = val.strip('"')
 
     def get_var(self, var, image=None):
         """
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [wic][PATCH v2] wic: fix parsing of 'bitbake -e' output
  2016-12-21 15:05   ` [wic][PATCH v2] " Ed Bartosh
@ 2016-12-21 17:16     ` Maciej Borzęcki
  0 siblings, 0 replies; 4+ messages in thread
From: Maciej Borzęcki @ 2016-12-21 17:16 UTC (permalink / raw)
  To: Ed Bartosh; +Cc: Patches and discussions about the oe-core layer

On Wed, Dec 21, 2016 at 4:05 PM, Ed Bartosh <ed.bartosh@linux.intel.com> wrote:
> Current parsing code can wrongly interpret arbitrary lines
> that are of 'key=value' format as legitimate bitbake variables.
>
> Implemented more strict parsing of key=value pairs using
> regular expressions.
>
> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
> ---
>  scripts/lib/wic/utils/oe/misc.py | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
> index fe188c9..2a2fcc9 100644
> --- a/scripts/lib/wic/utils/oe/misc.py
> +++ b/scripts/lib/wic/utils/oe/misc.py
> @@ -27,6 +27,7 @@
>  """Miscellaneous functions."""
>
>  import os
> +import re
>  from collections import defaultdict
>  from distutils import spawn
>
> @@ -148,21 +149,18 @@ class BitbakeVars(defaultdict):
>          self.default_image = None
>          self.vars_dir = None
>
> -    def _parse_line(self, line, image):
> +    def _parse_line(self, line, image, matcher=re.compile(r"^(\w+)=(.+)")):
>          """
>          Parse one line from bitbake -e output or from .env file.
>          Put result key-value pair into the storage.
>          """
>          if "=" not in line:
>              return
> -        try:
> -            key, val = line.split("=")
> -        except ValueError:
> +        match = matcher.match(line)
> +        if not match:
>              return
> -        key = key.strip()
> -        val = val.strip()
> -        if key.replace('_', '').isalnum():
> -            self[image][key] = val.strip('"')
> +        key, val = match.groups()
> +        self[image][key] = val.strip('"')
>
>      def get_var(self, var, image=None):
>          """
> --
> 2.1.4
>

Looks good to me.

Thanks for fixing this so quickly.

-- 
Maciej Borzecki
RnDity


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-21 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-21 14:19 [wic][PATCH] wic: fix parsing of 'bitbake -e' output Ed Bartosh
2016-12-21 14:31 ` Maciej Borzęcki
2016-12-21 15:05   ` [wic][PATCH v2] " Ed Bartosh
2016-12-21 17:16     ` Maciej Borzęcki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.