Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): prevent error on manifest element without children #6278

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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