- Notifications
You must be signed in to change notification settings - Fork95
Allow additional characters in query validation#1267
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
Summary by CodeRabbit
WalkthroughThis pull request updates the query validation logic by modifying the regular expression in the Changes
Assessment against linked issues
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
🪧 TipsChatThere are 3 ways to chat withCodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
backend/apps/core/validators.py (1)
90-95
:🛠️ Refactor suggestionUpdate the error message to match the new validation pattern.
The regex pattern has been properly updated to
^[\w .-]*$
to allow word characters, spaces, periods, and hyphens. However, the error message still only mentions "alphanumeric characters, hyphens, spaces, and underscores" without including periods (.) and the fact that word characters now include Unicode letters (non-ASCII characters).if not re.match(r"^[\w .-]*$", query): message = ( "Invalid query value provided. "- "Only alphanumeric characters, hyphens, spaces, and underscores are allowed."+ "Only word characters (letters, numbers, underscores), periods, hyphens, and spaces are allowed." ) raise ValidationError(message)
🧹 Nitpick comments (2)
backend/tests/apps/core/validators_test.py (2)
98-98
:Good test case addition for non-ASCII characters and periods.The addition of the test case
"çal Q. query"
properly validates that the new regex pattern accepts non-ASCII characters (ç) and periods (.).Consider expanding the test coverage by adding dedicated test cases in
test_invalid_query
for some of the specific invalid characters mentioned in the PR objectives (e.g.,!
,@
,#
, etc.) to ensure they're properly rejected.
78-94
:Enhance invalid query test coverage.The current test suite only verifies that queries with exclamation marks (
!
) are rejected. Since the PR defines several invalid characters, it would be beneficial to add more test cases to ensure all specified invalid characters are properly rejected.Consider adding more parameterized test cases to
test_invalid_query
to validate that queries containing other specified invalid characters (e.g.,@
,#
,$
, etc.) are also rejected correctly.@pytest.mark.parametrize( ("query", "error_message"), [ (5, "query must be a string."), ( "query!name", ( "Invalid query value provided. " "Only alphanumeric characters, hyphens, spaces, and underscores are allowed." ), ),+ (+ "query@name",+ (+ "Invalid query value provided. "+ "Only alphanumeric characters, hyphens, spaces, and underscores are allowed."+ ),+ ),+ (+ "query#name",+ (+ "Invalid query value provided. "+ "Only alphanumeric characters, hyphens, spaces, and underscores are allowed."+ ),+ ),+ # Add more invalid characters as needed ], )
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/apps/core/validators.py
(1 hunks)backend/tests/apps/core/validators_test.py
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: Run frontend e2e tests
- GitHub Check: Run frontend unit tests
- GitHub Check: Run backend tests
- GitHub Check: CodeQL (python)
- GitHub Check: CodeQL (javascript-typescript)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
Resolves#1257
Allowed Strings
.
,-
,(space),
/w
-> any word character (including Unicode letters, numbers, and underscores)Invalid strings:
which include special Characters -> !, @, #, $, %, ^, &, *, (, ), +, =, {, }, [, ], |, , :, ;, ", ', <, >, ?, /, `, ~