Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add trailing slash to regular expressions #22

Merged
merged 1 commit into from
May 5, 2022

Conversation

eduardoboucas
Copy link
Member

Which problem is this pull request solving?

This PR changes the regular expressions generated from a path declaration so that they contain an optional trailing slash.

So /foo will yield ^/foo/?$ instead of ^/foo$.

@eduardoboucas eduardoboucas added the type: feature code contributing to the implementation of a feature and/or user facing functionality label May 4, 2022
@eduardoboucas eduardoboucas requested a review from mraerino May 4, 2022 17:27
@@ -30,7 +30,7 @@ const generateManifest = ({ bundles = [], declarations = [], functions }: Genera
return
}

const pattern = 'pattern' in declaration ? new RegExp(declaration.pattern) : globToRegExp(declaration.path)

Choose a reason for hiding this comment

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

wait what is this 'pattern' in declaration? is that the same as declaration?.pattern? I almost never see in used

Copy link
Member Author

@eduardoboucas eduardoboucas May 4, 2022

Choose a reason for hiding this comment

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

Yes, but since declaration is a union type (DeclarationWithPath or DeclarationWithPattern) and the pattern property only exists in one of them, the in allows us to disambiguate. So if you do:

if ('pattern' in declaration) {
  // From this point on you know that `declaration` is of type
  // `DeclarationWithPattern` and so does the TypeScript compiler.
}

Copy link

@charliegroll charliegroll left a comment

Choose a reason for hiding this comment

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

test updates look kosher to me :shipit:

@fool
Copy link

fool commented May 4, 2022

Do we need to worry about the case where a customer wants different behavior for /path and /path/ ? I haven't seen requests for that, just wanted to mention it as a potential cost of this implementation.

@eduardoboucas eduardoboucas merged commit ffc12a4 into main May 5, 2022
Skn0tt pushed a commit to netlify/build that referenced this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants