Skip to content

fix: honour deprecated ParseErrorsWhitelist.UnknownFlagsHandling - #507

Merged
tomasaschan merged 1 commit into
spf13:masterfrom
lenamonj:fix-deprecated-whitelist-handling
Sep 6, 2026
Merged

fix: honour deprecated ParseErrorsWhitelist.UnknownFlagsHandling#507
tomasaschan merged 1 commit into
spf13:masterfrom
lenamonj:fix-deprecated-whitelist-handling

Conversation

@lenamonj

Copy link
Copy Markdown

getUnknownFlagsHandling checks the deprecated ParseErrorsWhitelist after the current ParseErrorsAllowlist, but the deprecated branch returns the Allowlist field:

// then, check deprecated ParseErrorsWhitelist:
if f.ParseErrorsWhitelist.UnknownFlagsHandling != ErrorOnUnknownFlag {
    return f.ParseErrorsAllowlist.UnknownFlagsHandling   // <- wrong struct
}

Control only reaches that line when ParseErrorsAllowlist.UnknownFlagsHandling == ErrorOnUnknownFlag, so it always returns ErrorOnUnknownFlag and setting the deprecated field does nothing at all. Callers still on ParseErrorsWhitelist.UnknownFlagsHandling silently lose the behaviour they asked for:

f := pflag.NewFlagSet("t", pflag.ContinueOnError)
f.ParseErrorsWhitelist.UnknownFlagsHandling = pflag.IgnoreUnknownFlag
f.Parse([]string{"--unknown-flag", "value"})   // returns "unknown flag: --unknown-flag"

The neighbouring ParseErrorsWhitelist.UnknownFlags bool is handled correctly, and TestIgnoreUnknownFlagsBackwardsCompat covers it - only the UnknownFlagsHandling field is affected, which is why it slipped through.

One identifier changed. The test follows the existing pattern: testParseWithUnknownFlagsAndPassToArgs takes an optional setup func so the same body can be driven from either struct, and TestIgnoreUnknownFlagsAndPassToArgsBackwardsCompat mirrors the existing TestIgnoreUnknownFlagsBackwardsCompat. With the fix reverted that test fails; with it, the suite is green.

@CLAassistant

CLAassistant commented Aug 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lenamonj
lenamonj force-pushed the fix-deprecated-whitelist-handling branch from 8097ad1 to 94000cc Compare September 4, 2026 01:25

@tomasaschan tomasaschan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@tomasaschan
tomasaschan merged commit c0d292e into spf13:master Sep 6, 2026
8 checks passed
@lenamonj
lenamonj deleted the fix-deprecated-whitelist-handling branch September 7, 2026 00:50
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.

3 participants