Skip to content

fix: treat a bare-string extra_keywords as one keyword - #10735

Open
FireChickenMP4 wants to merge 1 commit into
AstrBotDevs:masterfrom
FireChickenMP4:fix/10697-string-keywords-upstream
Open

FireChickenMP4 wants to merge 1 commit into
AstrBotDevs:masterfrom
FireChickenMP4:fix/10697-string-keywords-upstream

Conversation

@FireChickenMP4

@FireChickenMP4 FireChickenMP4 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Separate from #10697, which handles invalid regex entries. This one is about the
value's type.

extra_keywords is declared as a list in the config schema, but the loader fills
in missing keys and keeps the value it finds, so a hand-edited config can hold a
plain string:

"extra_keywords": "blocked"

self.keywords.extend(extra_keywords) then walks characters, so "blocked"
becomes seven one-character keywords. Any message containing one of those letters
is blocked: "hello world" is blocked because of the e and the o. The log line
only reports that a keyword matched, so nothing points back at extra_keywords.

The patch wraps a bare string in a list before the extend, and treats an empty
string as no keywords. Configs that already hold a list behave the same.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

A non-iterable value still raises TypeError at the extend, same as today; I
left that alone. Fixing this in the loader would mean type-checking every option,
so the normalisation stays local.

Verification:

pytest tests/test_content_safety_check.py -q
7 passed

Without the normalisation the string test fails: "the old clock" is blocked by the
single-character keywords.

`extra_keywords` is declared as a list in the config schema, but the loader
keeps whatever value it finds, so a hand-edited string is iterated character
by character and every character becomes its own keyword.

Normalise a bare string to a single-element list before extending the keyword
list, and treat an empty string as no keywords.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_content_safety_check.py" line_range="100-117" />
<code_context>
     assert stopped is expected_stopped
+
+
+def test_keywords_strategy_treats_string_config_as_one_pattern():
+    """A bare-string extra_keywords value is one keyword, not N char patterns.
+
+    The config schema declares a list, but a hand-edited config can hold a plain
+    string. Iterating it turns every character into its own keyword, so any
</code_context>
<issue_to_address>
**Tests are added against guidance**

When the new test cases are included, two new test functions are added, contrary to the repository instruction, so the change introduces test code the guidance says not to generate.

Remove the added test cases to follow the repository guidance.
</issue_to_address>

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_content_safety_check.py

This branch has not been deployed

No deployments
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