Skip to content

Commit e2b8f24

Browse files
committed
sysfs: make sanitize_sysfs_value() more resilient
1 parent 20e3645 commit e2b8f24

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sasutils/sysfs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030

3131
# Some VPDs contain weird characters...
3232
def sanitize_sysfs_value(value):
33-
return value.strip('\x00').encode('ascii', errors='replace').decode()
33+
try:
34+
value2 = value.strip('\x00')
35+
except TypeError:
36+
try:
37+
value2 = value.strip(b'\x00').decode('ascii', errors='replace')
38+
except Exception:
39+
value2 = str(value).strip('\x00')
40+
return value2.encode('ascii', errors='replace').decode()
3441

3542

3643
class SysfsNode(object):

0 commit comments

Comments
 (0)