manifest: validate() fixes
We need to be a bit more careful with our types. For example, the string "not-a-manifest" can be loaded as YAML, and evaluates to... itself. And the string 'manifest' sure is in the string 'not-a-manifest', so the "'manifest' not in data" check in validate() doesn't catch the invalidity. Then we try to index ['manifest'] in a string, which doesn't work, because string indexes must be integers. Boom. Fix it with extra type checking. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
7822a4c315
commit
cd55fcc255
|
@ -79,7 +79,12 @@ def validate(data):
|
|||
:param data: YAML manifest data as a string or object
|
||||
'''
|
||||
if isinstance(data, str):
|
||||
as_str = data
|
||||
data = yaml.safe_load(data)
|
||||
if not isinstance(data, dict):
|
||||
raise MalformedManifest(f'{as_str} is not a YAML dictionary')
|
||||
elif not isinstance(data, dict):
|
||||
raise TypeError(f'data type {type(data)} must be str or dict')
|
||||
|
||||
if 'manifest' not in data:
|
||||
raise MalformedManifest('manifest data contains no "manifest" key')
|
||||
|
|
Loading…
Reference in New Issue