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

autoInject regex pattern contains error #1663

Closed
freeart opened this issue Jun 13, 2019 · 3 comments
Closed

autoInject regex pattern contains error #1663

freeart opened this issue Jun 13, 2019 · 3 comments

Comments

@freeart
Copy link

freeart commented Jun 13, 2019

What version of async are you using?
3.0.1

Which environment did the issue occur in (Node version/browser version)
nodejs

What did you do? Please include a minimal reproducable case illustrating issue.
I found an error in autoInject when you use arrow function
https://regex101.com/r/RpedPY/1
regex doesn't work properly with "=>" symbol

What did you expect to happen?

What was the actual result?

@aearly
Copy link
Collaborator

aearly commented Jun 14, 2019

Do you have code that breaks? There is a secondary regex for arrow functions: https://github.com/caolan/async/blob/master/lib/autoInject.js#L6

@freeart
Copy link
Author

freeart commented Jun 14, 2019

var FN_ARGS = /^(?:async\s+)?(?:function)?\s*[^(]*\(\s*([^)]+)\s*\)(?:\s*{)/m;
var ARROW_FN_ARGS = /^(?:async\s+)?(?:function\s+)?\(?\s*([^)^=]+)\s*\)?(?:\s*=>)/m;

...

const src = func.toString().replace(STRIP_COMMENTS, '');
let match = src.match(FN_ARGS);
if (!match) {
    match = src.match(ARROW_FN_ARGS);
}

It breaks on let match = src.match(FN_ARGS);because match contains string !orderCache || !analysisCache for this function https://regex101.com/r/RpedPY/2

@aearly aearly closed this as completed in e1045be Jun 23, 2019
@aearly
Copy link
Collaborator

aearly commented Jun 23, 2019

Figured this one out. Thanks for the excellent example!

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

No branches or pull requests

2 participants