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: move internal regular expressions to static properties #5384

Merged
merged 6 commits into from
Apr 14, 2021
Merged

feat: move internal regular expressions to static properties #5384

merged 6 commits into from
Apr 14, 2021

Conversation

vaporoxx
Copy link
Contributor

Please describe the changes this PR makes and why it should be merged:

This moves the regular expressions used in the DataResolver class to static properties for external use.

Status and versioning classification:

  • I know how to update typings and have done so
  • This PR changes the library's interface (methods or parameters added)

@SpaceEEC
Copy link
Member

Using a static global regex with RegExp#exec will store a lastIndex on the object which messes with further calls to exec on different strings.

We'd either need to clone the regexp before scanning the string or use String#matchAll which seems to be supported on node v14 (node.green with string matchAll) and does that internally. (See mdn on Regexp.exec() and matchAll())

I didn't really test either, so feel free to correct me if I am wrong.

@vaporoxx
Copy link
Contributor Author

@SpaceEEC I was able to reproduce the problem you mentioned, tested it and it should be fixed now

@iCrawl iCrawl merged commit 207735c into discordjs:master Apr 14, 2021
@vaporoxx vaporoxx deleted the feat-regexp branch April 15, 2021 12:20
@iCrawl iCrawl added this to the Version 13 milestone Jun 27, 2021
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

Successfully merging this pull request may close these issues.

6 participants