Skip to content

Fix package filter policy validation of names with surrounding whitespace - #11298

Open
adityajai119 wants to merge 1 commit into
python-poetry:mainfrom
adityajai119:fix-package-filter-policy-validator-whitespace
Open

adityajai119 wants to merge 1 commit into
python-poetry:mainfrom
adityajai119:fix-package-filter-policy-validator-whitespace

Conversation

@adityajai119

Copy link
Copy Markdown

PackageFilterPolicy.normalize() strips whitespace from comma-separated names, but validator() checked the unstripped names against a strict regex. As a result, values such as \ oo, bar\ or \ PyTest, black \ were rejected by \poetry config installer.no-binary ...\ and --local\ configuration, even though they normalize correctly.

This strips each name in validator() so validation matches normalization. Adds a focused parametrized regression test.

Tests: 106 passed in tests/config/test_config.py; 79 passed in tests/console/commands/test_config.py; ruff check and format pass on changed test file.

@sourcery-ai sourcery-ai Bot 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.

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/config/test_config.py" line_range="78" />
<code_context>
+def test_package_filter_policy_validator_accepts_whitespace(
+    value: str, expected: set[str]
+) -> None:
+    assert PackageFilterPolicy.validator(value)
+    assert set(PackageFilterPolicy.normalize(value)) == expected
+
</code_context>
<issue_to_address>
**Invalid names remain accepted**

When the validator is changed to return `True` for every policy, `test_package_filter_policy_validator_accepts_whitespace` only asserts a truthy validator result at line 78; its normalization assertion at line 79 uses valid inputs. An unconditional `True` validator therefore passes while accepting invalid names such as `foo.bar`.

Add a rejection assertion for a policy containing an invalid package name.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: tests/config/test_config.py:78


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

Comment thread tests/config/test_config.py Resolved

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