Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dts string prop value parsing #21

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions fdt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,30 @@ def parse_dts(text: str, root_dir: str = '') -> FDT:
raise NotImplementedError("Not implemented property value: /bits/")
else:
prop_obj = PropStrings(prop_name)
for prop in prop_value.split('",'):
prop = prop.replace('"', "")
prop = prop.strip()
if len(prop) > 0:
expect_open = True
in_prop = False
prop = ''
for c in prop_value:
if c == '"' and not in_prop and expect_open:
prop = ''
in_prop = True
elif c == '"' and in_prop:
if not len(prop) > 0:
raise ValueError('Empty string')
prop_obj.append(prop)
in_prop = False
expect_open = False
elif in_prop:
prop += c
elif c == ',' and not expect_open:
expect_open = True
elif c == ' ':
continue
else:
raise ValueError(f'Invalid char: {c}')

if expect_open:
raise ValueError('Expected string after ,')
if curnode is not None:
curnode.append(prop_obj)

Expand Down