Skip to content
Snippets Groups Projects
Commit 776d3622 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix(cocoapods): add null checks for out of bound lines

Closes #5857, Closes #5858
parent e62cbff9
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,9 @@ export interface ParsedLine { ...@@ -27,6 +27,9 @@ export interface ParsedLine {
export function parseLine(line: string): ParsedLine { export function parseLine(line: string): ParsedLine {
const result: ParsedLine = {}; const result: ParsedLine = {};
if (!line) {
return result;
}
for (const regex of Object.values(regexMappings)) { for (const regex of Object.values(regexMappings)) {
const match = regex.exec(line.replace(/#.*$/, '')); const match = regex.exec(line.replace(/#.*$/, ''));
if (match && match.groups) { if (match && match.groups) {
......
...@@ -9,6 +9,16 @@ const fileContent = fs.readFileSync( ...@@ -9,6 +9,16 @@ const fileContent = fs.readFileSync(
describe('lib/manager/cocoapods/update', () => { describe('lib/manager/cocoapods/update', () => {
describe('updateDependency', () => { describe('updateDependency', () => {
it('handles undefined lines', () => {
const upgrade = {
depName: 'b',
managerData: { lineNumber: 999999999 },
currentValue: '1.2.3',
newValue: '2.0.0',
};
const res = updateDependency({ fileContent, upgrade });
expect(res).toBeNull();
});
it('replaces existing value', () => { it('replaces existing value', () => {
const upgrade = { const upgrade = {
depName: 'b', depName: 'b',
......
...@@ -24,6 +24,14 @@ export function updateDependency({ ...@@ -24,6 +24,14 @@ export function updateDependency({
const lines = fileContent.split('\n'); const lines = fileContent.split('\n');
const lineToChange = lines[managerData.lineNumber]; const lineToChange = lines[managerData.lineNumber];
if (!lineToChange) {
logger.warn(
{ fileContent, depName, currentValue, newValue },
'Undefined cocoapods lineToChange'
);
return null;
}
if (!lineContainsDep(lineToChange, depName)) { if (!lineContainsDep(lineToChange, depName)) {
return null; return null;
} }
......
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