Skip to content

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

Open
@nader-zouaoui

Description

@nader-zouaoui

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions