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.
let found = false;
let validateFunction: undefined | ((...args: unknown[]) => unknown);
let field: CoreH5PSemantics | undefined;
const field = semantics.fields.find(field => field.name === key);
let value: unknown = null;
for (const field of semantics.fields) {
if (field.name == key) {
if (semantics.optional) {
field.optional = true;
}
validateFunction = this[this.typeMap[field.type || '']].bind(this);
found = true;
break;
if (field) {
if (semantics.optional) {
field.optional = true;
}
const validateFunction = this[this.typeMap[field.type || '']].bind(this);
if (validateFunction) {
value = await validateFunction(groupObject[key], field);
groupObject[key] = value;
}
}
if (found && validateFunction) {
const val = await validateFunction(groupObject[key], field);
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;
if (value === null) {
delete groupObject[key];
}
}