Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#1190·superstruct

pattern (regex) does not return consistent output when using the global modifier

Author: brendonboshellCreated Jul 18, 2023Updated Aug 4, 2025
Labelsbug

In this example:

const s = require("superstruct");

const Query = s.object({
  url: s.pattern(s.string(), /^example/g),
});

const testQuery = {
  url: "example",
};

console.log(s.is(testQuery, Query), s.is(testQuery, Query));

It returns the following output:

% node index.js
true false

I would expect each call to is to return the same output. I suspect this is because of the stateful behaviour of regular expressions.

Source: ianstormtaylor/superstruct

View original on GitHubView discussion on GitHub