OptionString: Do not convert None to non-empty string 33/19033/2
authorVratko Polak <vrpolak@cisco.com>
Thu, 18 Apr 2019 12:19:24 +0000 (14:19 +0200)
committerVratko Polak <vrpolak@cisco.com>
Thu, 18 Apr 2019 14:20:55 +0000 (14:20 +0000)
Change-Id: I2947394a478bde3fe048aef99fd7b5a394764ae2
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
resources/libraries/python/OptionString.py

index d6cb40f..7c8b2d0 100644 (file)
@@ -93,8 +93,9 @@ class OptionString(object):
         return self
 
     def _check_and_add(self, part, prefixed):
-        """Convert to string, strip, add conditionally prefixed if non-empty.
+        """Convert to string, strip, conditionally add prefixed if non-empty.
 
+        Value of None is converted to empty string.
         Emptiness is tested before adding prefix.
 
         :param part: Unchecked part to add to list of parts.
@@ -104,7 +105,7 @@ class OptionString(object):
         :returns: The converted part without prefix, empty means not added.
         :rtype: str
         """
-        part = str(part).strip()
+        part = "" if part is None else str(part).strip()
         if part:
             prefixed_part = self.prefix + part if prefixed else part
             self.parts.append(prefixed_part)

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.