{"record":{"id":"85a558318e52cf17","repo":"badges/shields","slug":"invalid-flags-must-be-one-of-valid-flags","errorCode":null,"errorMessage":"Invalid flags, must be one of: ${VALID_FLAGS}","messagePattern":"Invalid flags, must be one of: (.+?)","errorType":"validation","errorClass":"InvalidParameter","httpStatus":400,"severity":"error","filePath":"services/dynamic/dynamic-regex.service.js","lineNumber":73,"sourceCode":"            required: false,\n            example: '$<amount>/$1',\n          },\n          {\n            name: 'flags',\n            description:\n              'Flags to be used when creating the regex: `i` = case-insensitive, `m` = multi-line mode, `s` = dot matches linebreaks. None by default.',\n            required: false,\n            example: VALID_FLAGS,\n          },\n        ),\n      },\n    },\n  }\n  static defaultBadgeData = { label: 'match' }\n\n  static validate(flags) {\n    if (flags?.split('')?.some(c => VALID_FLAGS.indexOf(c) === -1)) {\n      throw new InvalidParameter({\n        prettyMessage: `Invalid flags, must be one of: ${VALID_FLAGS}`,\n      })\n    }\n  }\n\n  static transform(buffer, search, replace, flags) {\n    // build re2 regex\n    let re2\n    try {\n      re2 = new RE2(search, flags)\n    } catch (error) {\n      if (error instanceof SyntaxError) {\n        throw new InvalidParameter({\n          prettyMessage: `Invalid re2 regex: ${error.message}`,\n        })\n      }\n      throw error\n    }","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/dynamic/dynamic-regex.service.js#L55-L91","documentation":"This InvalidParameter is thrown by the dynamic-regex (dynamic/json-regex style) service's validate step when the flags query parameter contains any character not present in VALID_FLAGS (the single-character regex modifiers allowed, e.g. 'i' and 'g'). Flags must be a string whose every character is an accepted regex flag. The check runs before any regex is compiled.","triggerScenarios":"Passing flags such as flags=m (unsupported modifier), flags=igm (contains unsupported 'm'), flags with spaces, or multi-letter flags like flags=giu where 'u' is not in VALID_FLAGS.","commonSituations":"Copying flags from PCRE/JS docs that include unsupported modifiers (m, s, u, x); combining flags as words ('global') instead of single letters; typos in badge URLs.","solutions":["Restrict the flags parameter to characters listed in VALID_FLAGS (e.g. i, g).","Remove unsupported modifiers from the URL; emulate multiline behavior within the regex body if needed.","URL-encode the flags value to avoid stray characters/space corruption."],"exampleFix":"// before\n/badge/dynamic/json.svg?url=...&query=...&search=version&replace=$1&flags=igm\n// after\n/badge/dynamic/json.svg?url=...&query=...&search=version&replace=$1&flags=gi","handlingStrategy":"validation","validationCode":"const VALID_FLAGS = 'ig';\nfunction validateFlags(flags) {\n  if (flags && [...flags].some(c => !VALID_FLAGS.includes(c))) {\n    throw new Error(`Invalid flags, must be one of: ${VALID_FLAGS}`);\n  }\n}\nvalidateFlags('gi'); // ok before calling the service","typeGuard":"function hasValidFlags(flags) {\n  return flags === undefined || [...flags].every(c => 'ig'.includes(c));\n}","tryCatchPattern":null,"preventionTips":["Use only single-character flags accepted by the service (check VALID_FLAGS in the source).","Do not copy PCRE modifiers (m, s, u, x) into the flags parameter.","URL-encode flag values to avoid stray characters."],"tags":["validation","regex","bad-request","parameters"],"backgroundTag":"invalid-parameter","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}