Skip to content

Add ParseCallbacks::allow_item() and ParseCallbacks::block_item(). #3245

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nicopauss
Copy link

Like allowlist_item and blocklist_item options, add new methods to ParseCallbacks, ParseCallbacks::allow_item() and ParseCallbacks::block_item(), to be able to allow and block items from being generated.

allowlist_* and blocklist_* options work with regexes and are inserted in a RegexSet.

There are two issues with this approach:

  1. In some cases we want to have more flexibility than just using regexes. If we want to have dynamic conditions to allow or block items, using regexes can be limited.
  2. RegexSet scales linearly with the number of elements inserted. This means that if we have a huge number of items that we want to allow or block, regexes and RegexSet are not necessarily the most appropriate data structures.

Using new methods in ParseCallbacks solves these two issues. We can manually decide the appropriate rules and data structure to match the items.

ParseCallbacks::allow_item() and ParseCallbacks::block_item() are always called after the allowlist_* and blocklist_* options, and allow or do not block the items by default respectively.

Like `allowlist_item` and `blocklist_item` options, add new methods to
`ParseCallbacks`, `ParseCallbacks::allow_item()` and
`ParseCallbacks::block_item()`, to be able to allow and block items from
being generated.

`allowlist_*` and `blocklist_*` options work with regexes and are
inserted in a RegexSet.

There are two issues with this approach:
1. In some cases we want to have more flexibility than just using
   regexes. If we want to have dynamic conditions to allow or block
   items, using regexes can be limited.
2. RegexSet scales linearly with the number of elements inserted. This
   means that if we have a huge number of items that we want to allow or
   block, regexes and RegexSet are not necessarily the most appropriate
   data structures.

Using new methods in `ParseCallbacks` solves these two issues.
We can manually decide the appropriate rules and data structure to match
the items.

`ParseCallbacks::allow_item()` and `ParseCallbacks::block_item()` are
always called after the `allowlist_*` and `blocklist_*` options, and
allow or do not block the items by default respectively.
@nicopauss nicopauss force-pushed the intersec/add-parse-callbacks-methods branch from 430055d to 89385ad Compare July 9, 2025 20:02
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.

1 participant