Skip to content

Commit

Permalink
fix(bundler): harden extract (#19839)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jan 14, 2023
1 parent 3a6cfac commit 2180f5b
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions lib/modules/manager/bundler/extract.ts
Expand Up @@ -73,8 +73,16 @@ export async function extractPackageFile(
while (lineNumber < lines.length && groupLine !== 'end') {
lineNumber += 1;
groupLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(groupLine)) {
logger.warn(
{ content, fileName, type: 'groupLine' },
'Bundler parsing error'
);
groupLine = 'end';
}
if (groupLine !== 'end') {
groupContent += formatContent(groupLine || '');
groupContent += formatContent(groupLine);
}
}
const groupRes = await extractPackageFile(groupContent);
Expand Down Expand Up @@ -104,8 +112,11 @@ export async function extractPackageFile(
lineNumber += 1;
sourceLine = lines[lineNumber];
// istanbul ignore if
if (sourceLine === null || sourceLine === undefined) {
logger.info({ content, fileName }, 'Undefined sourceLine');
if (!is.string(sourceLine)) {
logger.warn(
{ content, fileName, type: 'sourceLine' },
'Bundler parsing error'
);
sourceLine = 'end';
}
if (sourceLine !== 'end') {
Expand Down Expand Up @@ -135,6 +146,14 @@ export async function extractPackageFile(
while (lineNumber < lines.length && platformsLine !== 'end') {
lineNumber += 1;
platformsLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(platformsLine)) {
logger.warn(
{ content, fileName, type: 'platformsLine' },
'Bundler parsing error'
);
platformsLine = 'end';
}
if (platformsLine !== 'end') {
platformsContent += formatContent(platformsLine);
}
Expand All @@ -160,7 +179,15 @@ export async function extractPackageFile(
while (lineNumber < lines.length && ifLine !== 'end') {
lineNumber += 1;
ifLine = lines[lineNumber];
if (is.string(ifLine) && ifLine !== 'end') {
// istanbul ignore if
if (!is.string(ifLine)) {
logger.warn(
{ content, fileName, type: 'ifLine' },
'Bundler parsing error'
);
ifLine = 'end';
}
if (ifLine !== 'end') {
ifContent += formatContent(ifLine);
}
}
Expand Down

0 comments on commit 2180f5b

Please sign in to comment.