{"record":{"id":"1f9afe92a094c540","repo":"balderdashy/sails","slug":"invalid-regex-regex-supplied-to-skipregexeswr","errorCode":null,"errorMessage":"Invalid regex \"${regex}\" supplied to skipRegexesWrapper; ignoring.","messagePattern":"Invalid regex \"(.+?)\" supplied to skipRegexesWrapper; ignoring\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/router/bind.js","lineNumber":437,"sourceCode":"    };\n  };\n\n  /**\n   * Wrap a route in a helper function that first checks whether the URL matches\n   * any of a set of regexes, and if so, skips the defined handler.\n   *\n   * @param  {array}   regexes Array of regexes to match the URL against\n   * @param  {Function} fn      Middleware function to run if URL does NOT match regexes\n   * @return {Function} A middleware function\n   */\n  var skipRegexesWrapper = function(regexes, fn) {\n\n    // Remove anything that's not a regex\n    regexes = _.compact(regexes.map(function(regex) {\n      if (regex instanceof RegExp) {\n        return regex;\n      }\n      sails.log.warn('Invalid regex \"' + regex + '\" supplied to skipRegexesWrapper; ignoring.');\n      return undefined;\n    }));\n\n\n    return function(req, res, next) {\n\n      // Check for matches\n      for (var i = 0; i < regexes.length; i++) {\n        if (req.url.match(regexes[i])) {\n          // If we find one, bail out\n          return next();\n        }\n      }\n\n      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n      // TODO: Need to double-check on this, but shouldn't this call `enhancedFn`, instead of just `fn`?\n      // If so, then we can just make that change.  Otherwise, we need to do more here.\n      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/router/bind.js#L419-L455","documentation":"`skipRegexesWrapper` wraps route handling with regex-based skip logic. Every value in the regexes array must be a real RegExp instance; any non-RegExp entry is dropped and this warning is logged, so that path pattern silently won't be skipped.","triggerScenarios":"Passing strings (e.g. `'/^\\/api/'`) or other non-RegExp values into a skipRegexes config or policy option that feeds `skipRegexesWrapper`.","commonSituations":"Configuring skip patterns as strings in config/policies.js or custom middleware instead of RegExp literals — a common mistake since routes elsewhere use strings.","solutions":["Use RegExp literals instead of strings: `/^\\/api\\//` instead of `'/^\\/api\\//'`","Remove the invalid entries if skipping is not needed","Convert string patterns with `new RegExp(pattern)` at config definition"],"exampleFix":"// before\nskipRegexes: ['^/api/']\n// after\nskipRegexes: [/^\\/api\\//]","handlingStrategy":"type-guard","validationCode":"function assertRegexes(arr) {\n  arr.forEach(v => { if (!(v instanceof RegExp)) throw new TypeError('skipRegexes entries must be RegExp: ' + v); });\n}","typeGuard":"function isRegExpArray(v) {\n  return Array.isArray(v) && v.every(x => x instanceof RegExp);\n}","tryCatchPattern":null,"preventionTips":["Always write skip patterns as /.../ RegExp literals, never strings","Convert string patterns with new RegExp(s) if config comes from JSON/env","Add a startup validation for policy/middleware config"],"tags":["routing","regex","middleware","sails"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}