Skip to content

Commit

Permalink
sysfs: make sanitize_sysfs_value() more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
thiell committed Nov 12, 2024
1 parent 20e3645 commit e2b8f24
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sasutils/sysfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@

# Some VPDs contain weird characters...
def sanitize_sysfs_value(value):
return value.strip('\x00').encode('ascii', errors='replace').decode()
try:
value2 = value.strip('\x00')
except TypeError:
try:
value2 = value.strip(b'\x00').decode('ascii', errors='replace')
except Exception:
value2 = str(value).strip('\x00')
return value2.encode('ascii', errors='replace').decode()


class SysfsNode(object):
Expand Down

0 comments on commit e2b8f24

Please sign in to comment.