Skip to content

Match complete option names in environment defaults - #617

Merged
mkarg merged 1 commit into
cbeust:masterfrom
PHJ2000:fix-environment-option-name-boundary
Nov 2, 2026
Merged

mkarg merged 1 commit into
cbeust:masterfrom
PHJ2000:fix-environment-option-name-boundary

Conversation

@PHJ2000

@PHJ2000 PHJ2000 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Require an option-name boundary before reading its environment-provided value. With only --foobar present, querying --foo now returns null instead of consuming the suffix as a value.

Covers overlapping names, exact matches, and a flag at the end of the input. ./gradlew check passes all 341 tests on Java 21.

Fixes #616.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change preventing partial option-name matches in environment defaults.

No open issues 🎉

What changed in this PR

Fixes #616 by requiring a complete option-name match when reading environment defaults, so querying --foo no longer consumes part of --foobar as its value.

Changes:

  • Requires whitespace or end of input after the requested option name.
  • Adds regression tests for overlapping names, exact matches, and a flag at the end of input.
File Description
src/​test/​java/​com/​beust/​jcommander/​defaultprovider/​EnvironmentVariableDefaultProviderTest.java Adds option-boundary regression tests.
src/​main/​java/​com/​beust/​jcommander/​defaultprovider/​EnvironmentVariableDefaultProvider.java Adds a boundary check to the option-matching pattern.

Review effort: Balanced

@mkarg
mkarg merged commit 639b4d9 into cbeust:master Nov 2, 2026
1 check passed
@mkarg mkarg added the bug Bug label Nov 2, 2026
@mkarg mkarg self-assigned this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EnvironmentVariableDefaultProvider matches prefixes of longer option names

3 participants