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

Invalid regex (iso8601Pattern) when building with ajv ^8.8.2 #71

Closed
jakejscott opened this issue Dec 23, 2021 · 5 comments
Closed

Invalid regex (iso8601Pattern) when building with ajv ^8.8.2 #71

jakejscott opened this issue Dec 23, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@jakejscott
Copy link
Contributor

Describe the bug
When I run sls deploy I a regex error:

SyntaxError: Invalid regular expression: /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/: Invalid escape
      at new RegExp (<anonymous>)
      at defaultRegExp (C:\dev\test-slic-watch\nexus\node_modules\ajv\lib\core.ts:66:53)
      

I think it's this regex: https://github.com/fourTheorem/slic-watch/blob/main/serverless-plugin/config-schema.js#L6

To Reproduce
sls deploy

Expected behavior

Environment:

  • OS: Windows
  • Node.js Version: 14.18.0
  • NPM version: 6.14.15
  • Serverless Framework Version:
    Framework Core: 2.69.1 (local)
    Plugin: 5.5.1
    SDK: 4.3.0
    Components: 3.18.1

Additional context
We are using serverless-esbuild plugin which uses esbuild to build the code.
https://github.com/floydspace/serverless-esbuild

@jakejscott jakejscott added the bug Something isn't working label Dec 23, 2021
@eoinsha
Copy link
Contributor

eoinsha commented Dec 24, 2021

Thanks for reporting @jakejscott. I tried to reproduce with the test project:
https://github.com/fourTheorem/slic-watch/tree/fix-esbuild-regex/serverless-test-project
and haven't seen this yet. Can you check this test project and compare to your setup?
I'm also using the plugin in other projects with serverless-esbuild and haven't seen it yet.

@jakejscott
Copy link
Contributor Author

Yeah I'll have a go with adding esbuild in my fork of the test project add see if that's what is causing it. It might end up being something else

@jakejscott jakejscott changed the title Invalid regex (iso8601Pattern) when building with serverless-esbuild Invalid regex (iso8601Pattern) when building with ajv ^8.8.2 Jan 2, 2022
@jakejscott
Copy link
Contributor Author

Hey @eoinsha I've managed to reproduce the issue :) Our project is using "ajv": "^8.8.2". If you upgrade the test project to that version and run npm run test (which calls sls package) it will throw that regex error.

@jakejscott
Copy link
Contributor Author

Narrowed it down to this unicode flag that Ajv adds when creating the regex:

const iso8601Pattern = '^([\\+-]?\\d{4}(?!\\d{2}\\b))((-?)((0[1-9]|1[0-2])(\\3([12]\\d|0[1-9]|3[01]))?|W([0-4]\\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3([0-5]\\d|6[1-6])))([T\\s]((([01]\\d|2[0-3])((:?)[0-5]\\d)?|24\\:?00)([\\.,]\\d+(?!:))?)?(\\17[0-5]\\d([\\.,]\\d+)?)?([zZ]|([\\+-])([01]\\d|2[0-3]):?([0-5]\\d)?)?)?)?$';

const date = new Date().toISOString()
console.log('isValid', new RegExp(iso8601Pattern, 'u').test(date))

Error:

console.log('isValid', new RegExp(iso8601Pattern, 'u').test(date))
                       ^

SyntaxError: Invalid regular expression: /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/: Invalid escape
    at new RegExp (<anonymous>)
    at Object.<anonymous> (/mnt/c/dev/jakejscott/slic-watch/serverless-test-project/test.js:11:24)
    ```


@jakejscott
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants