MOBILE-4081 h5p: Fix cannot read tags of undefined
This commit is contained in:
		
							parent
							
								
									8d0412fa68
								
							
						
					
					
						commit
						922be9f9bc
					
				@ -493,32 +493,25 @@ 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 (field) {
 | 
			
		||||
                    if (semantics.optional) {
 | 
			
		||||
                        field.optional = true;
 | 
			
		||||
                    }
 | 
			
		||||
                        validateFunction = this[this.typeMap[field.type || '']].bind(this);
 | 
			
		||||
                        found = true;
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
                    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) {
 | 
			
		||||
                if (value === null) {
 | 
			
		||||
                    delete groupObject[key];
 | 
			
		||||
                }
 | 
			
		||||
                } else {
 | 
			
		||||
                    // Something exists in content that does not have a corresponding semantics field. Remove it.
 | 
			
		||||
                    delete groupObject.key;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return groupObject;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user