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

Syntax error when defining special regex characters in exclusions #24

Open
mondeja opened this issue Sep 15, 2023 · 0 comments
Open

Syntax error when defining special regex characters in exclusions #24

mondeja opened this issue Sep 15, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@mondeja
Copy link
Contributor

mondeja commented Sep 15, 2023

Expected Behavior

When I add a regex special character to an exclusion word I don't want to deal with the problem of regex-escaping them because is really confusing to add escaping characters to YAML. Additionally, the documentation of the action is not referrencing that exclusion words are regexes, it refers to them as "keywords".

Current Behavior

When I add a regex special character to an exclusion, the action raises a Syntax error. I can reproduce it locally with, for example:

> 'icon\nrequest\n[\n]'.split(/[\s\n]+/).map((keyword) => keyword.trim()).filter((keyword) => keyword.length > 0).reduce((memo, keyword) => memo.replace(new RegExp(keyword, 'igm'), ''), '[icon request] hello world')
Uncaught SyntaxError: Invalid regular expression: /[/: Unterminated character class

Possible Solution

Regex-escaping exclude keywords with a function like this:

function escapeRegExp(text) {
  return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

Other solution would be to define exclude keywords as regexes in the documentation and provide an example of regex-escaping them.

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

1 participant