Skip to content

fix(cmd): reject malformed subscribe filters - #4036

Open
axhatggg wants to merge 1 commit into
knative:mainfrom
axhatggg:fix-subscribe-filter-validation
Open

fix(cmd): reject malformed subscribe filters#4036
axhatggg wants to merge 1 commit into
knative:mainfrom
axhatggg:fix-subscribe-filter-validation

Conversation

@axhatggg

@axhatggg axhatggg commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #3941

Why

func subscribe --filter accepted malformed values, printed "Invalid pair:",
and continued — then wrote func.yaml anyway and exited 0. A user who typos a
filter in a script gets a silent misconfiguration: the function subscribes more
broadly than intended, and it only surfaces much later.

Separately, strings.Split was used where SplitN is needed, so legitimate
filter values containing "=" (e.g. foo=bar=baz) were also discarded.

What changed

  • use strings.SplitN(filter, "=", 2) so filter values containing "=" are preserved
  • extractFilterMap returns an error for a missing "=" or an empty key
  • the error propagates through updateOrAddSubscription to runSubscribe, so the
    command fails before f.Write() rather than after

Testing

  • TestExtractFilterMap — table-driven, 8 cases: valid filters, values containing
    "=", empty values, missing "=", and empty keys
  • TestSubscribeRejectsMalformedFilter — asserts cmd.Execute() returns an error
    and that func.yaml is left untouched
  • TestSubscribeAllowsFilterValueContainingEquals — asserts foo=bar=baz round-trips
  • Both end-to-end tests were confirmed failing before the fix was applied
  • make test and make check pass locally (Go 1.26.7, Linux)

extractFilterMap used strings.Split on "=", so a valid filter value containing "=" (foo=bar=baz) split into three parts and was silently dropped. Malformed values were printed and skipped, after which runSubscribe still called f.Write() - writing func.yaml without the requested filter and exiting 0.

Use strings.SplitN to preserve values containing "=", return an error for a missing "=" or an empty key, and propagate it through updateOrAddSubscription to runSubscribe so the command fails before anything is written.

Adds table-driven unit tests for extractFilterMap and end-to-end tests asserting cmd.Execute() returns an error and leaves func.yaml untouched.
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 2, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: axhatggg / name: axhatggg (6cbfb89)

@knative-prow

knative-prow Bot commented Sep 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: axhatggg
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Sep 2, 2026
@knative-prow

knative-prow Bot commented Sep 2, 2026

Copy link
Copy Markdown

Welcome @axhatggg! It looks like this is your first PR to knative/func 🎉

@knative-prow

knative-prow Bot commented Sep 2, 2026

Copy link
Copy Markdown

Hi @axhatggg. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd: subscribe silently ignores malformed --filter values

1 participant