Skip to content

Validate route filter definitions to reject spaces with clear error messages#40

Merged
ondratu merged 5 commits into
masterfrom
copilot/fix-filter-route-definition-error
Jan 7, 2026
Merged

Validate route filter definitions to reject spaces with clear error messages#40
ondratu merged 5 commits into
masterfrom
copilot/fix-filter-route-definition-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 7, 2026

Spaces in route filter definitions like @app.route('/api/< id:int>') were either silently registered as static routes (causing runtime errors) or raised unclear RuntimeError: Undefined route group filter ':int ' messages.

Changes

  • Added validation regex in poorwsgi/wsgi.py to detect spaces in filter definitions:

    • After <: < id:int>
    • Before >: <id:int >
    • After parameter name: <id :int>
    • After colon: <id: int>
  • Enhanced set_route method to validate URIs before processing and raise ValueError with actionable error message including correct format examples

  • Added test suite (tests/test_route_validation.py) covering valid routes, invalid routes with spaces in various positions, and error message quality

Error Message Improvement

Before:

@app.route('/api/<id:int >')
# RuntimeError: Undefined route group filter ':int '

After:

@app.route('/api/<id:int >')
# ValueError: Invalid route definition '/api/<id:int >': 
# Route filter definitions must not contain spaces. 
# Use '<name:filter>' format without any spaces. 
# Examples: '<id:int>', '<name:word>', '<value:float>'

Note: Spaces within :re: custom regex patterns remain valid, as they're part of the regex itself.

Original prompt

This section details on the original issue you should resolve

<issue_title>Error when there space in filter route definition</issue_title>
<issue_description>``` python
@app.route("/api/<entity_id: int>")

crash</issue_description>

<agent_instructions>There is a error when this route is used (because space). Create pull request with fix to right and clear error log for programmer.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 7, 2026 13:19
Co-authored-by: ondratu <6469029+ondratu@users.noreply.github.com>
Co-authored-by: ondratu <6469029+ondratu@users.noreply.github.com>
Co-authored-by: ondratu <6469029+ondratu@users.noreply.github.com>
Co-authored-by: ondratu <6469029+ondratu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error when there is space in filter route definition Validate route filter definitions to reject spaces with clear error messages Jan 7, 2026
Copilot AI requested a review from ondratu January 7, 2026 13:29
@ondratu ondratu marked this pull request as ready for review January 7, 2026 15:54
@ondratu ondratu merged commit 6aa4fbb into master Jan 7, 2026
5 checks passed
@ondratu ondratu deleted the copilot/fix-filter-route-definition-error branch January 7, 2026 15:55
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.

Error when there space in filter route definition

2 participants