Skip to content

Commit

Permalink
fix: podfile parsing on invalid yaml (react-native-community#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maushundb authored and thymikee committed Oct 18, 2019
1 parent 2fa7e1f commit b22d70a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PODS:
- MyPackage (1.0.0)

EXTERNAL SOURCES:
ExternalInterface:
:path: !ruby/object:Pathname
path: "../node_modules/MyOtherPackage/ios"

SPEC CHECKSUMS:
MyPackage: 77fd5fb102a4a5eedafa2c2b0245ceb7b7c15e45
MyOtherPackage: a9bb76128853e98a9ef6d12b0c8c91debc9bc475


PODFILE CHECKSUM: a8110dc7c367fc529b8b6a1084258784444d62ec

COCOAPODS: 1.7.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import getDependenciesFromPodfileLock from '../getDependenciesFromPodfileLock';

const path = require('path');

const PODFILES_PATH = path.join(__dirname, '../__fixtures__/');

describe('pods::getDependenciesFromPodfileLock', () => {
it('only parses parts of the lock file that are valid yaml', () => {
const podfileDeps = getDependenciesFromPodfileLock(
path.join(PODFILES_PATH, 'PodfileWithInvalidKey.lock'),
);
expect(podfileDeps).toEqual(['MyPackage', 'MyOtherPackage']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import chalk from 'chalk';
import {logger} from '@react-native-community/cli-tools';
import {safeLoad} from 'js-yaml';

const CHECKSUM_KEY = 'SPEC CHECKSUMS';

export default function getDependenciesFromPodfileLock(
podfileLockPath: string,
) {
Expand All @@ -18,5 +20,11 @@ export default function getDependenciesFromPodfileLock(
);
return [];
}
return Object.keys(safeLoad(fileContent)['SPEC CHECKSUMS'] || {});

// Previous portions of the lock file could be invalid yaml.
// Only parse parts that are valid
const tail = fileContent.split(CHECKSUM_KEY).slice(1);
const checksumTail = CHECKSUM_KEY + tail;

return Object.keys(safeLoad(checksumTail)[CHECKSUM_KEY] || {});
}

0 comments on commit b22d70a

Please sign in to comment.