Skip to content

Deprecate parsing non-lockfile content in LockfileParser#9502

Open
kurotaky wants to merge 1 commit intoruby:masterfrom
kurotaky:fix/lockfile-parser-reject-non-lockfile
Open

Deprecate parsing non-lockfile content in LockfileParser#9502
kurotaky wants to merge 1 commit intoruby:masterfrom
kurotaky:fix/lockfile-parser-reject-non-lockfile

Conversation

@kurotaky
Copy link
Copy Markdown

@kurotaky kurotaky commented Apr 23, 2026

What was the end-user or developer problem that led to this PR?

Bundler::LockfileParser#initialize silently accepts any string input — including Gemfiles, READMEs, or arbitrary text — producing an empty parser with no indication that the input was invalid. Downstream tooling such as bundler-audit (via its --gemfile-lock FILE option) has no way to confirm that the file it was handed is actually a lockfile. See #8932.

What is your fix for the problem, implemented in this PR?

Detect non-lockfile content at parse time by checking for any of the known section headers (GEM, GIT, PATH, PLATFORMS, DEPENDENCIES, etc.). Empty input is left untouched for backward compatibility.

Instead of raising immediately — which would be a hard break for anyone unknowingly relying on the old silent-accept behavior — the parser now:

  • emits a deprecation warning via SharedHelpers.feature_deprecated! announcing that a future Bundler version will raise LockfileError;
  • exposes a new LockfileParser#valid? predicate so callers can branch on the result without string-matching the deprecation message.

Specs cover both default and strict: true cases, for non-lockfile text and a Gemfile-as-lockfile regression.

Fixes #8932.

Make sure the following tasks are checked

  • Describe the problem / feature
  • Write tests for features and bug fixes
  • Write code to solve the problem
  • Make sure you follow the current code style and write meaningful commit messages without tags

Bundler::LockfileParser#initialize silently accepted any string input,
including Gemfiles or arbitrary text, producing an empty parser with
no indication that the input was invalid. This caused downstream
tooling like bundler-audit to operate on unvalidated content.

Detect non-lockfile content by checking for any of the known section
headers; empty input is left untouched for backward compatibility.
Rather than raising immediately, emit a deprecation warning via
SharedHelpers.feature_deprecated! announcing that a future Bundler
version will raise LockfileError. Expose LockfileParser#valid? so
callers can branch on the result without string-matching the message.

Fixes ruby#8932
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundler::LockfileParser#initialize will parse non-Gemfile.lock files, instead of raising an exception

1 participant