Skip to content
Snippets Groups Projects
Unverified Commit 2180f5bd authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix(bundler): harden extract (#19839)

parent 3a6cfacf
No related branches found
No related tags found
No related merge requests found
...@@ -73,8 +73,16 @@ export async function extractPackageFile( ...@@ -73,8 +73,16 @@ export async function extractPackageFile(
while (lineNumber < lines.length && groupLine !== 'end') { while (lineNumber < lines.length && groupLine !== 'end') {
lineNumber += 1; lineNumber += 1;
groupLine = lines[lineNumber]; groupLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(groupLine)) {
logger.warn(
{ content, fileName, type: 'groupLine' },
'Bundler parsing error'
);
groupLine = 'end';
}
if (groupLine !== 'end') { if (groupLine !== 'end') {
groupContent += formatContent(groupLine || ''); groupContent += formatContent(groupLine);
} }
} }
const groupRes = await extractPackageFile(groupContent); const groupRes = await extractPackageFile(groupContent);
...@@ -104,8 +112,11 @@ export async function extractPackageFile( ...@@ -104,8 +112,11 @@ export async function extractPackageFile(
lineNumber += 1; lineNumber += 1;
sourceLine = lines[lineNumber]; sourceLine = lines[lineNumber];
// istanbul ignore if // istanbul ignore if
if (sourceLine === null || sourceLine === undefined) { if (!is.string(sourceLine)) {
logger.info({ content, fileName }, 'Undefined sourceLine'); logger.warn(
{ content, fileName, type: 'sourceLine' },
'Bundler parsing error'
);
sourceLine = 'end'; sourceLine = 'end';
} }
if (sourceLine !== 'end') { if (sourceLine !== 'end') {
...@@ -135,6 +146,14 @@ export async function extractPackageFile( ...@@ -135,6 +146,14 @@ export async function extractPackageFile(
while (lineNumber < lines.length && platformsLine !== 'end') { while (lineNumber < lines.length && platformsLine !== 'end') {
lineNumber += 1; lineNumber += 1;
platformsLine = lines[lineNumber]; platformsLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(platformsLine)) {
logger.warn(
{ content, fileName, type: 'platformsLine' },
'Bundler parsing error'
);
platformsLine = 'end';
}
if (platformsLine !== 'end') { if (platformsLine !== 'end') {
platformsContent += formatContent(platformsLine); platformsContent += formatContent(platformsLine);
} }
...@@ -160,7 +179,15 @@ export async function extractPackageFile( ...@@ -160,7 +179,15 @@ export async function extractPackageFile(
while (lineNumber < lines.length && ifLine !== 'end') { while (lineNumber < lines.length && ifLine !== 'end') {
lineNumber += 1; lineNumber += 1;
ifLine = lines[lineNumber]; 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); ifContent += formatContent(ifLine);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment