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: validate pattern declarations #298

Merged
merged 7 commits into from
Feb 10, 2023
Merged

feat: validate pattern declarations #298

merged 7 commits into from
Feb 10, 2023

Conversation

eduardoboucas
Copy link
Member

Which problem is this pull request solving?

This PR parses into an AST any paths defined as regular expressions and:

  1. Throws an error if they contain negative lookaheads, as they aren't supported by the Go engine
  2. Converts named captured groups into regular captured groups, since the JavaScript syntax for named captured groups is different than the one used by the Go engine

List other issues or pull requests related to this problem

Supersedes #226.

@eduardoboucas eduardoboucas added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Feb 2, 2023
@eduardoboucas eduardoboucas requested review from a team and ascorbic February 2, 2023 09:14
danez
danez previously approved these changes Feb 2, 2023
Copy link
Contributor

@danez danez left a comment

Choose a reason for hiding this comment

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

Just one problem. We can fix this in a separate PR though

Otherwise LGTM 🤘

node/manifest.ts Outdated
throw new Error(
`Could not parse path declaration of function '${declaration.function}': ${(error as Error).message}`,
)
}
}

return pathToRegularExpression(declaration.path)
}

const getExcludedRegularExpression = (declaration: Declaration) => {
if ('pattern' in declaration && declaration.excludedPattern) {
Copy link
Contributor

@danez danez Feb 2, 2023

Choose a reason for hiding this comment

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

Suggested change
if ('pattern' in declaration && declaration.excludedPattern) {
if ('excludedPattern' in declaration && declaration.excludedPattern) {

Not really a change from this PR but seems it is currently wrong/broken? But I might be wrong and we only return the excludePattern when there is a pattern?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Fixed in 51d1023.

Assertion(path) {
// Lookaheads are not supported. If we find one, throw an error.
if (path.node.kind === 'Lookahead') {
throw new Error('Regular expressions with negative lookaheads are not supported')
Copy link
Member

Choose a reason for hiding this comment

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

It's not just negative lookaheads that aren't supported: positive lookaheads aren't either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah-ha! The comment was correct but the error message was not. Fixed in 2efa3f8.

@eduardoboucas eduardoboucas merged commit d8c44a3 into main Feb 10, 2023
@eduardoboucas eduardoboucas deleted the feat/parse-regex branch February 10, 2023 14:00
Skn0tt pushed a commit to netlify/build that referenced this pull request Apr 23, 2024
* feat: validate pattern declarations

* refactor: change import

* chore: add comment

* fix: add missing call to `serializePattern`

* refactor: wrap call to `parsePattern`

* refactor: update error message

* fix: look for `excludedPattern`
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.

None yet

3 participants