Skip to content

feat(routing): add regex converter support in routing - #2715

Open
infraredCoding wants to merge 4 commits into
falconry:masterfrom
infraredCoding:regex-route-pattern-support
Open

feat(routing): add regex converter support in routing#2715
infraredCoding wants to merge 4 commits into
falconry:masterfrom
infraredCoding:regex-route-pattern-support

Conversation

@infraredCoding

@infraredCoding infraredCoding commented Aug 20, 2026

Copy link
Copy Markdown

Add new builtin-converter RegexConverter to allow regex pattern matching when adding routes.

Closes #857

Summary of Changes

Add Regular Expression route conversion support

Related Issues

Closes #857

Pull Request Checklist

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Performed automated tests and code quality checks by running tox.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run tox -e docs, and inspect docs/_build/html/changes/ in the browser to ensure it renders correctly.)
  • LLM output, if any, has been carefully reviewed and tested by a human developer. (See also: Use of LLMs ("AI").)

This is my first PR in this repo and I might not be entirely sure how to change the documentations.

PR template inspired by the attrs project.

Add new builtin-converter RegexConverter to allow regex pattern matching when adding routes.

Closes falconry#857
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ea2b14d) to head (b607208).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2715   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         7990      8004   +14     
  Branches      1106      1107    +1     
=========================================
+ Hits          7990      8004   +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vytas7 vytas7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @infraredCoding , and thanks for this PR.

It is a solid start, however, we need to address a couple minor issues before merging:

  • A towncrier newsfragment is needed for this new feature. In this case the file should be named 857.newandimproved.rst.
  • It seems there are a couple of stray lines without code coverage. We need to add missing tests as Falcon requires 100% line and branch coverage.
  • Not critical, but it would be nice to add the new class to the table summarizing the available converters (in the docs).

Add new newsfragment for changelog regarding RegexConverter. Add RegexConverter usage in docs

Closes falconry#857
Add new tests for covering bad regex pattern and exception handling

Closes falconry#857
@infraredCoding

Copy link
Copy Markdown
Author

@vytas7 Thanks a lot for the feedback. I have added the newsfragment and the new test cases. Also, updated the routing docs

@infraredCoding
infraredCoding requested a review from vytas7 August 22, 2026 10:20
__slots__ = ('_pattern', '_compiled')

def __init__(self, pattern: str) -> None:
import re

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any specific reason to import re here inline?
Falcon's default router already uses re for sub-field matching, so this doesn't really win us anything.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No there was no particular reason I did that. I suppose it was simply just habit.

) from ex

def convert(self, value: str) -> str | None:
if self._compiled.fullmatch(value):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A more conceptual question here is whether we should support anything related groups, i.e., match the first group if it exists, or somehow support passing the information from the named groups, if any?

@CaselIT what do you think?

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.

Regular expression route converter

2 participants