Skip to content

Commit

Permalink
fix(cli): prevent error on manifest element without children (#6278)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Feb 9, 2023
1 parent 723e618 commit a7e374f
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions cli/src/cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,12 @@ export async function writeCordovaAndroidManifest(
const elementsToSearchNextIn = [];
for (const existingElement of existingElements) {
if (existingElement.name === pathTarget[0]) {
for (const el of existingElement.children) {
elementsToSearchNextIn.push(el);
if (existingElement.children) {
for (const el of existingElement.children) {
elementsToSearchNextIn.push(el);
}
} else {
elementsToSearchNextIn.push(existingElement);
}
}
}
Expand Down Expand Up @@ -926,7 +930,8 @@ export async function writeCordovaAndroidManifest(
}
if (
(requiredElement.children !== undefined) !==
(existingElement.children !== undefined)
(existingElement.children !== undefined) &&
requiredElement.children?.length !== 0
) {
return false;
} else {
Expand All @@ -948,11 +953,25 @@ export async function writeCordovaAndroidManifest(
return false;
}
}
} else {
let foundRequiredElement = false;
for (const existingElementItem of existingElement.children) {
const foundRequiredElementIn = doesElementMatch(
requiredElement,
existingElementItem,
);
if (foundRequiredElementIn) {
foundRequiredElement = true;
break;
}
}
if (!foundRequiredElement) {
return false;
}
}
}
return true;
};
/////////
const parsedExistingElements: any[] = [];
const rootKeyOfExistingElements =
Object.keys(existingElements)[0];
Expand Down Expand Up @@ -984,10 +1003,15 @@ export async function writeCordovaAndroidManifest(
...requiredElements[rootKeyOfRequiredElements]['$'],
};
}
parseXmlToSearchable(
requiredElements[rootKeyOfRequiredElements]['$$'],
rootOfRequiredElementsToAdd['children'],
);
if (
requiredElements[rootKeyOfRequiredElements]['$$'] !==
undefined
) {
parseXmlToSearchable(
requiredElements[rootKeyOfRequiredElements]['$$'],
rootOfRequiredElementsToAdd['children'],
);
}
parsedRequiredElements.push(rootOfRequiredElementsToAdd);
const elementsToSearch = findElementsToSearchIn(
parsedExistingElements,
Expand Down

0 comments on commit a7e374f

Please sign in to comment.