diff --git a/lib/index.ts b/lib/index.ts index 4bf8b75..0145191 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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); } diff --git a/lib/lock-file-parser.ts b/lib/lock-file-parser.ts index 6f2050f..5da3e12 100644 --- a/lib/lock-file-parser.ts +++ b/lib/lock-file-parser.ts @@ -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(); } diff --git a/lib/manifest-parser.ts b/lib/manifest-parser.ts index af4d7e4..cee3f17 100644 --- a/lib/manifest-parser.ts +++ b/lib/manifest-parser.ts @@ -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, @@ -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(); } diff --git a/package.json b/package.json index 5c10438..7c689ce 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/unit/lib/manifest-parser.test.ts b/test/unit/lib/manifest-parser.test.ts index ed75788..67348a4 100644 --- a/test/unit/lib/manifest-parser.test.ts +++ b/test/unit/lib/manifest-parser.test.ts @@ -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); + }); }); });