MOBILE-4081 h5p: Fix cannot read tags of undefined

main
Dani Palou 2022-10-05 16:01:54 +02:00
parent 8d0412fa68
commit 922be9f9bc
1 changed files with 14 additions and 21 deletions

View File

@ -493,31 +493,24 @@ export class CoreH5PContentValidator {
} }
// Find semantics for name=key. // Find semantics for name=key.
let found = false; const field = semantics.fields.find(field => field.name === key);
let validateFunction: undefined | ((...args: unknown[]) => unknown); let value: unknown = null;
let field: CoreH5PSemantics | undefined;
for (const field of semantics.fields) { if (field) {
if (field.name == key) { if (semantics.optional) {
if (semantics.optional) { field.optional = true;
field.optional = true; }
}
validateFunction = this[this.typeMap[field.type || '']].bind(this); const validateFunction = this[this.typeMap[field.type || '']].bind(this);
found = true; if (validateFunction) {
break; value = await validateFunction(groupObject[key], field);
groupObject[key] = value;
} }
} }
if (found && validateFunction) { if (value === null) {
const val = await validateFunction(groupObject[key], field); delete groupObject[key];
groupObject[key] = val;
if (val === null) {
delete groupObject[key];
}
} else {
// Something exists in content that does not have a corresponding semantics field. Remove it.
delete groupObject.key;
} }
} }