Skip to content

Syntax error when defining special regex characters in exclusions #24

Description

@mondeja

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions