Skip to content

Path negation #379

Open
Open
@blakeembrey

Description

@blakeembrey
Member

It comes up often that people want to be able to exclude a route from matching: #378, #268, #252, #99, and more.

With the removal of direct regex input in v8 it's no longer possible to use the workaround of ((?!login).*). To create a simpler version of this feature, I'm proposing adding new syntax to v8 to support it.

Proposal 1: Add regex params back from < v8

Allow (?!...) directly again.

Pros: "Just works"
Cons: Hard to ensure it'll remain safe and secure from ReDoS. Hard to understand, kind of magic if you aren't familiar with regex.

Proposal 2: Add simplified regex params with a new syntax

Combine regex parameters and a meta character like ! to indicate negation. For example, :path!(login).

Pros: Generate safe regex. Can be clearer to read.
Cons: It's either a positive or negative match, can't combine a|b|c|!login or something.

Proposal 3: Add meta character to existing path

Combine path features with a meta character. For example, /api{!/login}.

Pros: No need to re-introduce regex features.
Cons: Very unclear what happens in the example. It would technically only match /api, and you need something confusing like /api{!/login}{/*path} which is a mess to read.

Recommendation

Proposal 2 is the most straightforward since regex is already planned to be re-introduced. Feel free to add other possibilities.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @blakeembrey

        Issue actions

          Path negation · Issue #379 · pillarjs/path-to-regexp