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 error when parsing version of some PNPM lockfiles #8315

Merged
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
2 changes: 1 addition & 1 deletion npm_and_yarn/lib/dependabot/npm_and_yarn/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def self.run_yarn_command(command, fingerprint: nil)
end

def self.pnpm_lockfile_version(pnpm_lock)
pnpm_lock.content.match(/^lockfileVersion: '?(?<version>[\d.]+)/)[:version]
pnpm_lock.content.match(/^lockfileVersion: ['"]?(?<version>[\d.]+)/)[:version]
end

def self.dependencies_with_all_versions_metadata(dependency_set)
Expand Down
18 changes: 18 additions & 0 deletions npm_and_yarn/spec/dependabot/npm_and_yarn/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,24 @@
)
end
end

context "using double quotes to surround lockfileVersion" do
before do
stub_request(:get, File.join(url, "pnpm-lock.yaml?ref=sha"))
.with(headers: { "Authorization" => "token token" })
.to_return(
status: 200,
body: fixture("github", "pnpm_lock_quotes_content.json"),
headers: json_header
)
end

it "parses a version properly" do
expect(file_fetcher_instance.ecosystem_versions).to match(
{ package_managers: { "pnpm" => an_instance_of(Integer) } }
)
end
end
end

context "with an npm-shrinkwrap.json but no package-lock.json file" do
Expand Down
18 changes: 18 additions & 0 deletions npm_and_yarn/spec/fixtures/github/pnpm_lock_quotes_content.json

Large diffs are not rendered by default.