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: support quoted keys in inline tables #15

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export function buildDepGraph(
includeDevDependencies,
);
const pkgDetails: PkgInfo = manifest.pkgInfoFrom(manifestFileContents);
const pkgSpecs: PoetryLockFileDependency[] = lockFile.packageSpecsFrom(
lockFileContents,
);
const pkgSpecs: PoetryLockFileDependency[] =
lockFile.packageSpecsFrom(lockFileContents);
return poetryDepGraphBuilder.build(pkgDetails, dependencyNames, pkgSpecs);
}
5 changes: 3 additions & 2 deletions lib/lock-file-parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as toml from 'toml';
import * as toml from '@iarna/toml';

export function packageSpecsFrom(
lockFileContents: string,
): PoetryLockFileDependency[] {
const lockFile: PoetryLockFile = toml.parse(lockFileContents);
const lockFile = toml.parse(lockFileContents) as unknown as PoetryLockFile;

if (!lockFile.package) {
throw new LockFileNotValid();
}
Expand Down
10 changes: 7 additions & 3 deletions lib/manifest-parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as toml from 'toml';
import * as toml from '@iarna/toml';

export function pkgInfoFrom(manifestFileContents: string) {
let manifest: PoetryManifestType;
try {
manifest = toml.parse(manifestFileContents);
manifest = toml.parse(
manifestFileContents,
) as unknown as PoetryManifestType;
return {
name: manifest.tool.poetry.name,
version: manifest.tool.poetry.version,
Expand All @@ -17,7 +19,9 @@ export function getDependencyNamesFrom(
manifestFileContents: string,
includeDevDependencies: boolean,
): string[] {
const manifest: PoetryManifestType = toml.parse(manifestFileContents);
const manifest = toml.parse(
manifestFileContents,
) as unknown as PoetryManifestType;
if (!manifest.tool?.poetry) {
throw new ManifestFileNotValid();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"prepare": "npm run build"
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"@snyk/cli-interface": "^2.9.2",
"@snyk/dep-graph": "^1.23.0",
"debug": "^4.2.0",
"toml": "^3.0.0",
"tslib": "^2.0.0"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/lib/manifest-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,13 @@ describe('when loading manifest files', () => {
const poetryDependencies = getDependencyNamesFrom('[tool.poetry]', false);
expect(poetryDependencies.length).toBe(0);
});

it('should handle quoted keys in inline tables', () => {
const fileContents = `[tool.poetry.dependencies]
pkg_a = {"version" = "^1.0"}`;
const poetryDependencies = getDependencyNamesFrom(fileContents, false);
expect(poetryDependencies.length).toBe(1);
expect(poetryDependencies.includes('pkg_a')).toBe(true);
});
});
});