extensionSystem: Check metadata types
We currently check that an extension provides required metadata properties, but then assume that all properties have the expected type. It turns out that this is putting too much trust in extensions, so add an appropriate check. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5347 Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2272>
This commit is contained in:
parent
6df0002b29
commit
56d0b6d831
@ -310,11 +310,29 @@ var ExtensionManager = class {
|
||||
throw new Error(`Failed to parse metadata.json: ${e}`);
|
||||
}
|
||||
|
||||
let requiredProperties = ['uuid', 'name', 'description', 'shell-version'];
|
||||
const requiredProperties = [{
|
||||
prop: 'uuid',
|
||||
typeName: 'string',
|
||||
}, {
|
||||
prop: 'name',
|
||||
typeName: 'string',
|
||||
}, {
|
||||
prop: 'description',
|
||||
typeName: 'string',
|
||||
}, {
|
||||
prop: 'shell-version',
|
||||
typeName: 'string array',
|
||||
typeCheck: v => Array.isArray(v) && v.length > 0 && v.every(e => typeof e === 'string'),
|
||||
}];
|
||||
for (let i = 0; i < requiredProperties.length; i++) {
|
||||
let prop = requiredProperties[i];
|
||||
const {
|
||||
prop, typeName, typeCheck = v => typeof v === typeName,
|
||||
} = requiredProperties[i];
|
||||
|
||||
if (!meta[prop])
|
||||
throw new Error(`missing "${prop}" property in metadata.json`);
|
||||
if (!typeCheck(meta[prop]))
|
||||
throw new Error(`property "${prop}" is not of type ${typeName}`);
|
||||
}
|
||||
|
||||
if (uuid != meta.uuid)
|
||||
|
Loading…
Reference in New Issue
Block a user