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

RegExp topics when it has the global flag g set, the test() function will advance the lastIndex #1619

Open
nader-zouaoui opened this issue Sep 13, 2023 · 0 comments · May be fixed by #1620
Open

Comments

@nader-zouaoui
Copy link

nader-zouaoui commented Sep 13, 2023

Describe the bug
When setting a RegExp in the list of topics to subscribe to, and that regular expression has the global flag set. The output of the list of topics to subscribe to become indeterministic

To Reproduce
Here is a sample of topics and a regex that produce the problem

const topics = [
    "affiliate-AffiliateCreated",
    "payment-PaymentCreated",
    "products-ProductCreated",
    "booking-BookingCreated",
    "auth-UserCreated",
    "shop-ShopCreated",
    "wallet-TransactionCreated",
    "auth-UserNewSessionCreated",
    "comments-CommentCreated",
    "works-WorkCreated",
    "landing-page-LandingPageBannerItemCreated",
    "booking-AvailabilityCreated",
    "queue-QueueCreated",
    "blogs-BlogCreated",
    "categories-CategoriesCreated",
    "auth-UserCreatedNewSession",
    "auth-ClientCreated"
]
let rg = /(.*)(Created)(.*)/gi
console.log(topics.filter(topic=> rg.test(topic))

Expected behavior

It is supposed to return the same array.

Environment:
NodeJS 18..

Additional context
The description of the problem

image

@nader-zouaoui nader-zouaoui linked a pull request Sep 13, 2023 that will close this issue
nader-zouaoui added a commit to nader-zouaoui/kafkajs that referenced this issue May 31, 2024
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 a pull request may close this issue.

1 participant