fix(python): decode the Pipfile as TOML - #346
Open
arpitjain099 wants to merge 1 commit into
Open
arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
ParsePipfile declares toml struct tags and then decodes the file with
json.NewDecoder. A Pipfile is TOML, so the decode fails on the first line of
every real file, the error is logged at WARN (invisible without -v), and the
function returns an empty graph. Every package declared in a Pipfile is absent
from the dependency graph rather than merely unresolved, so nothing is looked
up and the scan reports no components for it.
The repo already depends on BurntSushi/toml and already reads TOML this way in
golang/gopkg.go and rust/cargo.go, so this is the same call.
Decoding as TOML then exposes the second half: a Pipfile entry is either a bare
specifier, requests = "==2.25.1", or an inline table carrying extras, markers or
a VCS source, django = {version = "==3.2.4", extras = ["bcrypt"]}. Against
map[string]string the table form errors and abandons the rest of the file, so
the entries are read as any and the version pulled out of either shape, with the
leading == stripped the way ParsePipfileLock already does.
The repo's own test/python case 2 shows the effect: its fixture is a valid
Pipfile declaring elasticsearch, and the case produced an empty tree.
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParsePipfiledeclares TOML struct tags and then decodes with a JSON decoder:A Pipfile is TOML, so the decode fails on the first line of every real file. The error is logged at WARN, which is invisible on a default run, and the function returns a graph with no children. The packages are absent from the graph rather than present-but-unresolved, so no lookup happens for any of them.
The repo's own
test/pythoncase 2 shows it. The fixture is a valid Pipfile declaringelasticsearch, and onmasterthe case produces an empty tree:[[source]]is the first line of the file, andsis the character the JSON decoder chokes on.The change
BurntSushi/tomlis already a direct dependency, andgolang/gopkg.goandrust/cargo.goalready read TOML withtoml.NewDecoder(reader).Decode(&x), so the first half is that same call.Swapping the decoder then exposes the second half. A Pipfile entry is either a bare specifier or an inline table carrying extras, markers or a VCS source:
Against
map[string]stringthe table form errors out and takes the rest of the file with it, which I hit while testing: a four package Pipfile came back with one entry. So the maps are read asanyand the version pulled out of either shape, with the leading==stripped the wayParsePipfileLockalready does at line 65. A table with noversion, such as a git or path dependency, contributes the package with an empty version rather than being dropped.Verification
With the change,
test/pythoncase 2 goes from an empty tree toelasticsearch:*. It does not fully pass in my checkout: the expected tree iselasticsearch:8.9.0with its transitives, and resolving*to a concrete version needs the remote registry, which my sandbox has no network for. So the parse half is fixed and the resolve half I could not exercise here.opensca/sca/python/pip_test.gocovers the parse half without a network: a Pipfile with a bare specifier, a*, an inline table withversionandextras, a git table with no version, and a[dev-packages]entry. It asserts all five are present, the versions are stripped, and only the dev one is markedDevelop. Onmasterit fails withgot 0 dependencies [], want 5.go test ./...gives the same package-level results before and after this change:test/java,test/php,test/pythonandtest/rubyfail either way in my environment, all of them wanting network or a local toolchain.